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

Typescript definition misleading #23

Closed
diondirza opened this issue Apr 23, 2019 · 3 comments
Closed

Typescript definition misleading #23

diondirza opened this issue Apr 23, 2019 · 3 comments

Comments

@diondirza
Copy link
Contributor

Hey guys, I start using this plugin with TS support in my codebase, and I use a custom function for origin field for cors options. Which I found the sample for it in your test file here

https://github.com/fastify/fastify-cors/blob/master/test/cors.test.js#L240.

But I got an error when using this kind of function signature, that TS told me about incompatible types for my function. When I look out on the d.ts file is supposed to be originCallback type

https://github.com/fastify/fastify-cors/blob/master/index.d.ts#L7

I think that type is for the second parameter in the function right? And the definition should be

type originCustom = (header: string, cb: originCallback) => void;
....
origin?: string | boolean | RegExp | string[] | RegExp[] | originCustom; // not originCallback

am I correct here, or the test is misguided me?

@mcollina
Copy link
Member

I think the tests win, so they types are going to be wrong. Would you like to send a PR?

@diondirza
Copy link
Contributor Author

Sure man, PR submitted. 🚀

@diondirza
Copy link
Contributor Author

Thanks for landing the fix, this issue should be closed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants