From 402b52ccbf043d5103746e09a4bf38c3ecd81fd5 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Oct 2020 10:13:34 +0200 Subject: [PATCH] fix: add `use` to types (#9) --- README.md | 6 +++++- index.d.ts | 7 ++++++- test/types/index.ts | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc2856f..413a286 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This plugin adds full [Express](http://expressjs.com) compatibility to Fastify, it exposes the same `use` function of Express, and it allows you to use any Express middleware or application.
-| **Note** | This plugin should not be used as a long-term solution, it aims to help you have a smooth transition from Express to Fastify, but you should migrate your Express specific code to Fastify during time. | +| **Note** | This plugin should not be used as a long-term solution, it aims to help you have a smooth transition from Express to Fastify, but you should migrate your Express specific code to Fastify over time. | | ---- | :---- | ## Install @@ -144,6 +144,10 @@ async function subsystem (fastify, opts) { } ``` +## TypeScript support + +To use this module with TypeScript, make sure to install `@types/express`. + ## Middlewares alternatives Fastify offers some alternatives to the most commonly used middlewares, following, you can find a list. diff --git a/index.d.ts b/index.d.ts index 55f429c..42fb81a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,13 @@ import { Application } from 'express' import { FastifyPluginCallback } from 'fastify' -declare module "fastify" { +declare module 'fastify' { interface FastifyInstance { + /** + * Express middleware function + */ + use: Application['use'] + /** * Express application instance */ diff --git a/test/types/index.ts b/test/types/index.ts index a98270b..996bc1c 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -6,3 +6,7 @@ const app = Fastify() app.register(fastifyExpress) app.express.disable('x-powered-by') + +app.use('/world', (_req, res) => { + res.sendStatus(200) +})