# Error in using expressMiddleware

**URL:** <https://community.apollographql.com/t/error-in-using-expressmiddleware/8415>\
**Category:** Server\
**Tags:** server, typescript\
**Created:** [February 8, 2025, 3:06pm UTC](https://community.apollographql.com/t/error-in-using-expressmiddleware/8415 "2025-02-08T15:06:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehdi\_Anoosheh](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/mehdi_anoosheh/32/5693_2.png) [@Mehdi\_Anoosheh](https://community.apollographql.com/u/Mehdi_Anoosheh)\
**Post date:** [February 8, 2025, 3:06pm UTC](https://community.apollographql.com/t/error-in-using-expressmiddleware/8415/1 "2025-02-08T15:06:28Z")

</div>

Hi  
in this code I tried to use middleWare in express typescript  
but when I type:  
app.use(‘/graphql’, expressMiddleware(server));  
I receive this error:  
" No overload matches this call.  
The last overload gave the following error.  
Argument of type ‘RequestHandler\<ParamsDictionary, any, any, ParsedQs, Record\<string, any\>\>’ is not assignable to parameter of type ‘Application\<Record\<string, any\>\>’.  
Type ‘RequestHandler\<ParamsDictionary, any, any, ParsedQs, Record\<string, any\>\>’ is missing the following properties from type ‘Application\<Record\<string, any\>\>’: init, defaultConfiguration, engine, set, and 63 more.ts(2769)  
index.d.ts(168, 5): The last overload is declared here."

this is my code:  
import { ApolloServer } from ‘@apollo/server’;  
import { expressMiddleware } from ‘@apollo/server/express4’;  
import { ApolloServerPluginDrainHttpServer } from ‘@apollo/server/plugin/drainHttpServer’;  
import express from ‘express’;  
import http from ‘http’;  
import cors from ‘cors’;  
import { typeDefs, resolvers } from ‘./graphql’;  
import { Database } from ‘…/lib/types’;  
interface MyContext {  
token?: string;  
db?: Database;  
}

const app = express();  
const httpServer = http.createServer(app);  
const server = new ApolloServer({  
typeDefs,  
resolvers,  
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],  
});

await server.start();  
app.use(cors());  
app.use(express.json());  
app.use(express.urlencoded({ extended: true }));

app.use(‘/graphql’, expressMiddleware(server)); //causes error

await new Promise((resolve) =\> httpServer.listen({ port: 4000 }, resolve));  
console.log(`🚀 Server ready at http://localhost:4000/`);

---

<div class="post-metadata">

**Author:** ![ahk](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/ahk/32/5895_2.png) [@ahk](https://community.apollographql.com/u/ahk)\
**Post date:** [March 17, 2025, 1:03pm UTC](https://community.apollographql.com/t/error-in-using-expressmiddleware/8415/2 "2025-03-17T13:03:13Z")

</div>

We have the same issue when using the example in Get Started page. “typescript”: “^5.8.2”, tsconfig:

```json
{
  "compilerOptions": {
    "rootDirs": ["src"],
    "outDir": "dist",
    "lib": ["es2020"],
    "target": "es2020",
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "types": ["node"]
  }
}

```

---

<div class="post-metadata">

**Author:** ![michaeldouglasdev](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/michaeldouglasdev/32/4911_2.png) [@michaeldouglasdev](https://community.apollographql.com/u/michaeldouglasdev)\
**Post date:** [March 17, 2025, 1:53pm UTC](https://community.apollographql.com/t/error-in-using-expressmiddleware/8415/3 "2025-03-17T13:53:28Z")

</div>

In the past, when I received an error similar to this, it was because I was not passing the context (interface and object) to Apollo Server.

---

<div class="post-metadata">

**Author:** ![tushar03](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tushar03](https://community.apollographql.com/u/tushar03)\
**Post date:** [April 4, 2025, 1:52pm UTC](https://community.apollographql.com/t/error-in-using-expressmiddleware/8415/4 "2025-04-04T13:52:22Z")

</div>

Update dependency version @types/express 5.0.1 to “@types/express”: “^4.17.17”
