Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): Origin within OriginFunction can be undefined #237

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
"version": "8.2.0",
"description": "Fastify CORS",
"main": "index.js",
"types": "index.d.ts",
"types": "types/index.d.ts",
"scripts": {
"coverage": "tap --cov --coverage-report=html test",
"lint": "npm run lint:standard && npm run lint:typescript",
"lint": "standard",
"lint:fix": "standard --fix",
"lint:standard": "standard",
"lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin test/*.ts",
"test": "npm run unit && npm run typescript",
"test:ci": "npm run lint && tap test/*.test.js --coverage-report=lcovonly && npm run typescript",
"typescript": "tsd",
"unit": "tap test/*.test.js"
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap test/*.test.js"
},
"keywords": [
"fastify",
Expand Down
6 changes: 0 additions & 6 deletions test/named-import.test-d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion index.d.ts → types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type FastifyCorsHook =
| 'onSend'

declare namespace fastifyCors {
export type OriginFunction = (origin: string, callback: OriginCallback) => void;
export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void;

export interface FastifyCorsOptions {
/**
Expand Down
8 changes: 8 additions & 0 deletions test/index.test-d.ts → types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fastify from 'fastify'
import { expectType } from 'tsd'
import fastifyCors, {
FastifyCorsOptionsDelegate,
FastifyCorsOptionsDelegatePromise,
Expand Down Expand Up @@ -310,3 +311,10 @@ appHttp2.register(fastifyCors, {
})

appHttp2.register(fastifyCors, delegate)

appHttp2.register(fastifyCors, {
hook: 'preParsing',
origin: function (origin) {
expectType<string|undefined>(origin)
},
})