|
1 | 1 | import { FastifyPluginCallback } from 'fastify'; |
2 | | -import Piscina from 'piscina'; |
| 2 | +import { Piscina } from 'piscina'; |
3 | 3 |
|
4 | | -type PiscinaOptions = typeof Piscina extends { |
5 | | - new (options?: infer T): Piscina; |
6 | | -} |
7 | | - ? T |
8 | | - : never; |
| 4 | +type PiscinaOptions = NonNullable<ConstructorParameters<typeof Piscina>[0]>; |
9 | 5 |
|
10 | | -export interface FastifyPiscinaPool extends Piscina {} |
| 6 | +type FastifyPiscinaPluginType = FastifyPluginCallback<PiscinaOptions>; |
11 | 7 |
|
12 | | -// Most importantly, use declaration merging to add the custom property to the Fastify type system |
13 | 8 | declare module 'fastify' { |
14 | 9 | interface FastifyInstance { |
15 | | - piscina: FastifyPiscinaPool; |
16 | | - runTask: FastifyPiscinaPool['run']; |
| 10 | + piscina: fastifyPiscina.FastifyPiscinaPool; |
| 11 | + runTask: fastifyPiscina.FastifyPiscinaRunTask; |
17 | 12 | } |
18 | 13 | } |
19 | 14 |
|
20 | | -declare const fastifyPiscina: FastifyPluginCallback<PiscinaOptions>; |
21 | | -export default fastifyPiscina; |
| 15 | +declare namespace fastifyPiscina { |
| 16 | + export type FastifyPiscinaPool = Piscina; |
| 17 | + export type FastifyPiscinaRunTask = Piscina['run']; |
| 18 | + |
| 19 | + export type FastifyPiscinaPluginOptions = PiscinaOptions; |
| 20 | + |
| 21 | + export const fastifyPiscina: FastifyPiscinaPluginType; |
| 22 | + export { fastifyPiscina as default }; |
| 23 | +} |
| 24 | + |
| 25 | +declare function fastifyPiscina(...params: Parameters<FastifyPiscinaPluginType>): ReturnType<FastifyPiscinaPluginType>; |
| 26 | +export = fastifyPiscina; |
0 commit comments