graphql / express-graphql

Create a GraphQL HTTP server with Express.
MIT License
6.34k stars 538 forks source link

TypeScript - merge declarations for request and response types #789

Open U-4-E-A opened 2 years ago

U-4-E-A commented 2 years ago
app.use(
    '/graphql',
    expressGraphQL((req, res) => ({
        schema,
        context: {
            req,
            res,
            currentUser: req.user,
            db,
            confirmCurrentUser: (): void => {
                if (typeof req.user === 'undefined') {
                res.status(401)
         }
      }
    },
  })
)

I get TS errors for req.user ("Property 'user' does not exist on type 'IncomingMessage'.ts(2339)") and res.status ("Property 'status' does not exist on type 'ServerResponse'.ts(2339)"). Is there a guide on how to merge declarations to add custom properties? Thanks.