1 | import fp from './plugin';
|
2 | import fastify, { FastifyPluginCallback, FastifyPluginAsync, FastifyError, FastifyInstance, FastifyPluginOptions } from 'fastify';
|
3 | import { expectAssignable, expectError } from 'tsd'
|
4 |
|
5 | interface Options {
|
6 | foo: string
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 | const pluginCallback: FastifyPluginCallback = (fastify, options, next) => { }
|
12 | expectAssignable<FastifyPluginCallback>(fp(pluginCallback))
|
13 |
|
14 | const pluginCallbackWithTypes = (fastify: FastifyInstance, options: FastifyPluginOptions, next: (error?: FastifyError) => void): void => { }
|
15 | expectAssignable<FastifyPluginCallback>(fp(pluginCallbackWithTypes))
|
16 |
|
17 | expectAssignable<FastifyPluginCallback>(fp((fastify: FastifyInstance, options: FastifyPluginOptions, next: (error?: FastifyError) => void): void => { }))
|
18 |
|
19 | expectAssignable<FastifyPluginCallback>(fp(pluginCallback, '' ))
|
20 | expectAssignable<FastifyPluginCallback>(fp(pluginCallback, {
|
21 | fastify: '',
|
22 | name: '',
|
23 | decorators: {
|
24 | fastify: [ '' ],
|
25 | reply: [ '' ],
|
26 | request: [ '' ]
|
27 | },
|
28 | dependencies: [ '' ]
|
29 | }))
|
30 |
|
31 | const pluginCallbackWithOptions: FastifyPluginCallback<Options> = (fastify, options, next) => {
|
32 | expectAssignable<string>(options.foo)
|
33 | }
|
34 |
|
35 | expectAssignable<FastifyPluginCallback<Options>>(fp(pluginCallbackWithOptions))
|
36 |
|
37 |
|
38 |
|
39 | const pluginAsync: FastifyPluginAsync = async (fastify, options) => { }
|
40 | expectAssignable<FastifyPluginAsync>(fp(pluginAsync))
|
41 |
|
42 | const pluginAsyncWithTypes = async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise<void> => { }
|
43 | expectAssignable<FastifyPluginAsync>(fp(pluginAsyncWithTypes))
|
44 |
|
45 | expectAssignable<FastifyPluginAsync>(fp(async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise<void> => { }))
|
46 | expectAssignable<FastifyPluginAsync>(fp(pluginAsync, '' ))
|
47 | expectAssignable<FastifyPluginAsync>(fp(pluginAsync, {
|
48 | fastify: '',
|
49 | name: '',
|
50 | decorators: {
|
51 | fastify: [ '' ],
|
52 | reply: [ '' ],
|
53 | request: [ '' ]
|
54 | },
|
55 | dependencies: [ '' ]
|
56 | }))
|
57 |
|
58 | const pluginAsyncWithOptions: FastifyPluginAsync<Options> = async (fastify, options) => {
|
59 | expectAssignable<string>(options.foo)
|
60 | }
|
61 |
|
62 | expectAssignable<FastifyPluginAsync<Options>>(fp(pluginAsyncWithOptions))
|
63 |
|
64 |
|
65 |
|
66 | const server = fastify()
|
67 | server.register(fp(pluginCallback))
|
68 | server.register(fp(pluginCallbackWithTypes))
|
69 | server.register(fp(pluginCallbackWithOptions))
|
70 | server.register(fp(pluginAsync))
|
71 | server.register(fp(pluginAsyncWithTypes))
|
72 | server.register(fp(pluginAsyncWithOptions))
|