Next.js: [request] better typescript type for `next.config.js` NextConfig

Created on 24 Jan 2020  路  7Comments  路  Source: vercel/next.js

Feature request

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

i only see this, but any not a good type

declare type NextConfig = any;

if have a type/interface for this
we can more easy write a next.config or a config plugin

Describe the solution you'd like

A clear and concise description of what you want to happen.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Most helpful comment

Just leaving my use case here after #8044 was closed without much considerations:

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

Documentation for config is incomplete and spread out. In-editor autocomplete solves this via types.

Describe the solution you'd like

Export types of next.config.js so that people can use JSDOC to get autcomplete for the config via

/**
 * @type {import('next').Config}
 */
const config = {
  // your config here
};
module.exports = config;

Describe alternatives you've considered

Declare the types locally starting from https://github.com/zeit/next.js/blob/287961ed9142a53f8e9a23bafb2f31257339ea98/packages/next/next-server/server/config.ts#L12-L65

All 7 comments

Just leaving my use case here after #8044 was closed without much considerations:

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

Documentation for config is incomplete and spread out. In-editor autocomplete solves this via types.

Describe the solution you'd like

Export types of next.config.js so that people can use JSDOC to get autcomplete for the config via

/**
 * @type {import('next').Config}
 */
const config = {
  // your config here
};
module.exports = config;

Describe alternatives you've considered

Declare the types locally starting from https://github.com/zeit/next.js/blob/287961ed9142a53f8e9a23bafb2f31257339ea98/packages/next/next-server/server/config.ts#L12-L65

I just used a similar approach for typing relay's configuration file :

// @ts-check

/**
 * @type import("relay-compiler/lib/bin/RelayCompilerMain").Config
 */
module.exports = {
  // free auto-complete and type-checking yay!
};

It's a great addition for discoverability.

they don't want type for it
https://github.com/zeit/next.js/pull/10275

See #13429

See #13429

It doesn't look like that PR adds a public type. It was suggested (https://github.com/vercel/next.js/pull/13429#issuecomment-634621879) but it's not apparent how I would import the config type.

Gatsby exposes really good types for their config, which allows you to strongly type the JavaScript config file using JSDoc as described above.

This is not one of our current priorities but I'm open to review a PR that adds types for Next.js configurations (similar to #13429 which was closed due to being quite outdated)

Was this page helpful?
0 / 5 - 0 ratings