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.
Steps to reproduce the behavior, please provide code snippets or a repository:
@types/next declarations.next and initiate a server.next module in a TypeScript custom server.next module should be typed properly (see declarations on DefinitelyTyped for reference)Using 8.1.0 + DefinitelyTyped typings:

Using canary:

v8.1.1-canary.47It 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.
@huv1k @Timer Hey! This is still an issue and can be reproduced with the steps given by @resir014.
Having the same issue. any solution so far? I had to downgrade to version next@^8.1.0 to make it work.
@Msordet @lomse I think the fixes made in https://github.com/zeit/next.js/pull/7547 only added some more additional types to the next.d.ts module, but didn't actually fix the actual issue that the types in index.d.ts (that doesn't include the types for next.d.ts) still takes precedence since it's defined on the types key on package.json.
I'll try to figure something out tomorrow.
Turns out I forgot to add this info in the first post. It's also worth noting that if I import next/dist/server/next directly, the types work as normal.
thanks for your investigation @resir014 , can confirm that import next from 'next/dist/server/next' fixes the problem
Looks like https://github.com/zeit/next.js/pull/7726 will fix this.
Most helpful comment
Looks like https://github.com/zeit/next.js/pull/7726 will fix this.