import fp from './plugin'; import fastify, { FastifyPluginCallback, FastifyPluginAsync, FastifyError, FastifyInstance, FastifyPluginOptions } from 'fastify'; import { expectAssignable, expectError } from 'tsd' interface Options { foo: string } // Callback const pluginCallback: FastifyPluginCallback = (fastify, options, next) => { } expectAssignable(fp(pluginCallback)) const pluginCallbackWithTypes = (fastify: FastifyInstance, options: FastifyPluginOptions, next: (error?: FastifyError) => void): void => { } expectAssignable(fp(pluginCallbackWithTypes)) expectAssignable(fp((fastify: FastifyInstance, options: FastifyPluginOptions, next: (error?: FastifyError) => void): void => { })) expectAssignable(fp(pluginCallback, '' )) expectAssignable(fp(pluginCallback, { fastify: '', name: '', decorators: { fastify: [ '' ], reply: [ '' ], request: [ '' ] }, dependencies: [ '' ] })) const pluginCallbackWithOptions: FastifyPluginCallback = (fastify, options, next) => { expectAssignable(options.foo) } expectAssignable>(fp(pluginCallbackWithOptions)) // Async const pluginAsync: FastifyPluginAsync = async (fastify, options) => { } expectAssignable(fp(pluginAsync)) const pluginAsyncWithTypes = async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise => { } expectAssignable(fp(pluginAsyncWithTypes)) expectAssignable(fp(async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise => { })) expectAssignable(fp(pluginAsync, '' )) expectAssignable(fp(pluginAsync, { fastify: '', name: '', decorators: { fastify: [ '' ], reply: [ '' ], request: [ '' ] }, dependencies: [ '' ] })) const pluginAsyncWithOptions: FastifyPluginAsync = async (fastify, options) => { expectAssignable(options.foo) } expectAssignable>(fp(pluginAsyncWithOptions)) // Fastify register const server = fastify() server.register(fp(pluginCallback)) server.register(fp(pluginCallbackWithTypes)) server.register(fp(pluginCallbackWithOptions)) server.register(fp(pluginAsync)) server.register(fp(pluginAsyncWithTypes)) server.register(fp(pluginAsyncWithOptions))