Next.js: Create types for the configuration in next.config.js (and the NextConfig type)

Created on 21 Jul 2019  路  3Comments  路  Source: vercel/next.js

Feature request

Is your feature request related to a problem? Please describe.

Since I transpile a next.config.ts to next.config.js, it would be good to have typings for the configuration object. This is what is currently typed as any in https://github.com/zeit/next.js/blob/fce7e4eaee45e89557ceaa81fbd42057f8596e22/packages/next-server/server/next-server.ts#L37

This is also a problem when using the programmatic API, since the conf property on the options given to next is typed as any:

import next from "next";
const app = next({
  conf // any
});

Describe the solution you'd like

The previous types provided by @types/next and @types/next-server can be seen here:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/next-server/next-config.d.ts

Perhaps the easiest solution is to type NextConfig with something similar to the version that @types/next-server is based on:
https://github.com/zeit/next.js/blob/7.0.0/server/config.js#L9-L20

Describe alternatives you've considered

The option that I see is to maintain types for the configuration object in parallel to this repository, or simply use the configuration untyped.

Most helpful comment

We're currently not planning on allowing next.config.ts, and I wouldn't recommend adding an intermediate build step for just one config file.

Types can be used via JSDoc, it'll help developers to annotate their next.config.js files.

image

All 3 comments

We're currently not planning on allowing next.config.ts, and I wouldn't recommend adding an intermediate build step for just one config file.

We're currently not planning on allowing next.config.ts, and I wouldn't recommend adding an intermediate build step for just one config file.

Types can be used via JSDoc, it'll help developers to annotate their next.config.js files.

image

Any movement on this?

Was this page helpful?
0 / 5 - 0 ratings