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

Better typings #325

Closed
dev101 opened this issue Jan 9, 2024 · 1 comment · Fixed by #326 · May be fixed by dev101/fastify-traps#1
Closed

Better typings #325

dev101 opened this issue Jan 9, 2024 · 1 comment · Fixed by #326 · May be fixed by dev101/fastify-traps#1

Comments

@dev101
Copy link
Contributor

dev101 commented Jan 9, 2024

#289 was not enough as I missed another typo:

FastifyPluginCallback should be imported from fastify, not from fastify-plugin.

Actually, I'd recommend to follow typings best practices:

  • namespace plugin and its options
  • export const and default

Here is my take for index.d.ts:

import { FastifyPluginCallback } from 'fastify'

type FastifyTrapsPlugin = FastifyPluginCallback<fastifyTraps.FastifyTrapsOptions>

declare namespace fastifyTraps {

  export interface FastifyTrapsOptions {
    timeout?: number
    onSignal?: (signal: 'SIGTERM' | 'SIGINT') => void
    onClose?: () => void
    onTimeout?: (timeout: number) => void
    onError?: (error: Error|any) => void
    strict?: boolean
  }

  export const fastifyTraps: FastifyTrapsPlugin
  export { fastifyTraps as default }
}

declare function fastifyTraps(
  ...params: Parameters<FastifyTrapsPlugin>
): ReturnType<FastifyTrapsPlugin>

export = fastifyTraps
@dnlup
Copy link
Owner

dnlup commented Jan 11, 2024

Thanks @dev101 for reporting this, would like to open a PR?

dev101 added a commit to dev101/fastify-traps that referenced this issue Jan 12, 2024
This was referenced Jan 12, 2024
dnlup pushed a commit that referenced this issue Jan 15, 2024
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

Successfully merging a pull request may close this issue.

2 participants