Skip to content

Commit

Permalink
fix: add use to types (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Oct 22, 2020
1 parent a0f23a8 commit 402b52c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br/>

| **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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ const app = Fastify()
app.register(fastifyExpress)

app.express.disable('x-powered-by')

app.use('/world', (_req, res) => {
res.sendStatus(200)
})

0 comments on commit 402b52c

Please sign in to comment.