[canary] built-in type declarations for `next()` missing
See original GitHub issueBug report
Describe the bug
Encountered this bug while trying to upgrade the custom-server-typescript example to the latest canary version of Next.js.
When I try to initiate a server in my custom TypeScript server, the built-in TypeScript declarations doesn’t seem to include the exported next() function used to initiate a server.
Before, initiating a next server works like this:
// ./server/index.ts
import * as next from 'next'
// ...
const app = next({ dev })
However, when I try to upgrade to canary and do the same, calling next() gives me this error:
// ./server/index.ts
import * as next from 'next'
// ...
const app = next({ dev }) // Error!
Cannot invoke an expression whose type lacks a call signature. Type 'typeof import("<snip>/node_modules/next/types/index")' has no compatible call signatures.
See “Additional context” for more information. I’ll update this issue as I see more possible fixes.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Upgrade the next package in the mentioned example to latest canary version.
- Remove the old
@types/nextdeclarations. - Try to import
nextand initiate a server. - See error.
Expected behavior
- No type errors when importing the default
nextmodule in a TypeScript custom server. - Base
nextmodule should be typed properly (see declarations on DefinitelyTyped for reference)
Screenshots
Using 8.1.0 + DefinitelyTyped typings:

Using canary:

System information
- OS: macOS 10.14.5
- Browser (if applies): Chrome
- Version of Next.js:
v8.1.1-canary.47
Additional context
It seems like the type declarations passed into package.json (types/index.d.ts) only includes the next/next-server helper types. However, it doesn’t actually include the actual declaration of the next() function that exists on the main file (server/next.js).
Well, we seem to have the declarations for the main file over here, but since we have the types key set in package.json it’s ignored in favour of the declaration file without the next() declaration!
It’s also worth noting that if I import next/dist/server/next directly, the types work as normal.
See declarations on DefinitelyTyped for reference.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
Looks like https://github.com/zeit/next.js/pull/7726 will fix this.
Turns out I forgot to add this info in the first post. It’s also worth noting that if I import
next/dist/server/nextdirectly, the types work as normal.