-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
chore: add test for fastify-plugin usage #33
Conversation
@SimenB Hi! Just had a quick look at this. I think the issue likely resides inside https://github.com/fastify/fastify-plugin/blob/master/plugin.d.ts#L3-L17 I'm able to resolve the issue by making the following edits to the above code. (note: these edits where made directly to the Code Modificationsimport {
FastifyPluginAsync,
FastifyPluginCallback,
FastifyPluginOptions,
RawServerDefault,
FastifyTypeProviderDefault
} from 'fastify'
// ---------------------------------------------------------------------------------
// Utility Types
// ---------------------------------------------------------------------------------
export type ExtractFastifyPluginAsyncParams<T> = T extends FastifyPluginAsync<
infer Options,
infer Server,
infer TypeProvider
> ? {
Options: Options,
Server: Server,
TypeProvider: TypeProvider
} : {
Options: FastifyPluginOptions,
Server: RawServerDefault,
TypeProvider: FastifyTypeProviderDefault,
}
export type ExtractFastifyPluginCallbackParams<T> = T extends FastifyPluginCallback<
infer Options,
infer Server,
infer TypeProvider
> ? {
Options: Options,
Server: Server,
TypeProvider: TypeProvider
} : {
Options: FastifyPluginOptions,
Server: RawServerDefault,
TypeProvider: FastifyTypeProviderDefault,
}
/**
* This function does three things for you:
* 1. Add the `skip-override` hidden property
* 2. Check bare-minimum version of Fastify
* 3. Pass some custom metadata of the plugin to Fastify
* @param fn Fastify plugin function
* @param options Optional plugin options
*/
export default function fp<Plugin, Params extends ExtractFastifyPluginAsyncParams<Plugin>>(fn: Plugin, options?: PluginMetadata): FastifyPluginAsync<Params['Options'], Params['Server'], Params['TypeProvider']>;
export default function fp<Plugin, Params extends ExtractFastifyPluginAsyncParams<Plugin>>(fn: Plugin, options?: string): FastifyPluginAsync<Params['Options'], Params['Server'], Params['TypeProvider']>;
export default function fp<Plugin, Params extends ExtractFastifyPluginCallbackParams<Plugin>>(fn: Plugin, options?: PluginMetadata): FastifyPluginCallback<Params['Options'], Params['Server'], Params['TypeProvider']>;
export default function fp<Plugin, Params extends ExtractFastifyPluginCallbackParams<Plugin>>(fn: Plugin, options?: string): FastifyPluginCallback<Params['Options'], Params['Server'], Params['TypeProvider']>; So, the above is a quick draft that should in theory work, but needs review from the Fastify team for overall correctness. Note, I'm not too familiar with the @RafaelGSS Any thoughts on updating the Hope this helps! |
@sinclairzx81 / @SimenB could you confirm if the patch fastify/fastify-plugin#192 fixes this issue? |
@RafaelGSS Heya. Can confirm the updates on fastify/fastify-plugin#192 do enable the TS tests on this branch to complete successfully. |
Co-authored-by: Manuel Spigolon <[email protected]>
Sweet! Good timing with that PR 😀 |
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
I tried using
FastifyPluginAsyncTypebox
and ran into issues withfastify-plugin
. This PR is (for now at least) just a failing test./cc @sinclairzx81