diff --git a/types/fastify-jwt/fastify-jwt-tests.ts b/types/fastify-jwt/fastify-jwt-tests.ts index 9015990b25..814ed20301 100644 --- a/types/fastify-jwt/fastify-jwt-tests.ts +++ b/types/fastify-jwt/fastify-jwt-tests.ts @@ -1,5 +1,5 @@ import { IncomingMessage, Server, ServerResponse } from "http"; -import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify-jwt"; +import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; const fastify: FastifyInstance = { jwt: { diff --git a/types/fastify-jwt/index.d.ts b/types/fastify-jwt/index.d.ts index 801a135f84..1fa14c30a1 100644 --- a/types/fastify-jwt/index.d.ts +++ b/types/fastify-jwt/index.d.ts @@ -3,24 +3,33 @@ // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 +import fastify = require("fastify"); import { Secret, SignOptions, VerifyOptions, VerifyCallback, SignCallback, DecodeOptions } from 'jsonwebtoken'; -export interface FastifyInstance { - jwt: jwt; +declare module "fastify" { + interface FastifyInstance { + jwt: jwt; + } + + interface jwt { + sign: (payload: any, options?: SignOptions, callback?: SignCallback) => void; + verify: (token: string, options?: VerifyOptions, callback?: VerifyCallback) => void; + decode: (token: string, options?: DecodeOptions) => null | { [key: string]: any } | string; + secret: Secret; + } + + interface FastifyRequest { + jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise | null | { [key: string]: any } | string; + } + + interface FastifyReply { + jwtSign: (payload: any, options?: SignOptions | SignCallback, next?: SignCallback) => void; + } } -export interface jwt { - sign: (payload: any, options?: SignOptions, callback?: SignCallback) => void; - verify: (token: string, options?: VerifyOptions, callback?: VerifyCallback) => void; - decode: (token: string, options?: DecodeOptions) => null | { [key: string]: any } | string; - secret: Secret; -} +declare function fastifyJwt (): void; -export interface FastifyRequest { - jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise | null | { [key: string]: any } | string; -} +declare namespace fastifyJwt {} -export interface FastifyReply { - jwtSign: (payload: any, options?: SignOptions | SignCallback, next?: SignCallback) => void; -} +export = fastifyJwt; \ No newline at end of file diff --git a/types/fastify-jwt/package.json b/types/fastify-jwt/package.json new file mode 100644 index 0000000000..948a91ff5b --- /dev/null +++ b/types/fastify-jwt/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "fastify": "^1.11.2" + } +} \ No newline at end of file