Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create types for the configuration in next.config.js (and the NextConfig type) #8044

Closed
eweilow opened this issue Jul 21, 2019 · 6 comments
Closed

Comments

@eweilow
Copy link

eweilow commented Jul 21, 2019

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.

@timneutkens
Copy link
Member

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.

@evgenymarkov
Copy link

evgenymarkov commented Aug 26, 2019

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

@zenVentzi
Copy link

Any movement on this?

@tylerbrostrom
Copy link

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

Snowpack’s official TypeScript templates use @type annotations in this way. Makes for great DX (and could be made better if they were to add annotations).

Implementing a NextConfig type seems like it might be a pain in the butt, especially if it’s to be integrated into the codebase (as opposed to a third-party Definitely Typed package). Might be more of a maintenance burden than it’s worth?

@timneutkens would you be open to a PR integrating a NextConfig type? I figured you might have a better idea of how feasible/worthwhile this might be 🙂 Thanks!

@timneutkens
Copy link
Member

@timneutkens would you be open to a PR integrating a NextConfig type? I figured you might have a better idea of how feasible/worthwhile this might be 🙂 Thanks!

Sure there's already multiple PRs to add such a type but they have not been merged yet given they were incomplete/did not have tests. If you open a new PR we'd be happy to take a look.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants