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

Tracking branch for Next.js’s upcoming TypeScript #458

Closed
wants to merge 1 commit into from

Conversation

fionawhim
Copy link
Contributor

The current 8.1.1 canary track includes native TypeScript support, which
includes official types for Next.js objects and out-of-the-box
TypeScript compilation. This is good! But it means we have to adapt some
of our existing TypeScript stuff.

As of this writing, Next.js enforces that the app directory contain its
own tsconfig.json file (vercel/next.js#7333), so this PR adds those as
necessary, inheriting from the parent package’s configuration. It also
requires a handful of specific configurations, so those are included as
well (vercel/next.js#7361) in those files.

This change also hoists acorn and acorn-dynamic-import because those two
packages need to be in a consistent place relative to each other and
webpack. (vercel/next.js#6240)

Currently the 'next' module does not export a type for its constructor
function, so we switch 'import next' to 'const next = require' to avoid
the typechecking.

We add "export {}" to the bottom of files that don’t do their own import
/ exporting to avoid an error due to the required "isolatedModules"
setting. (These can be removed if "isolatedModules" is removed.)

The bulk of the changes are updating _app and _document classes to the
nice new types.

The current 8.1.1 canary track includes native TypeScript support, which
includes official types for Next.js objects and out-of-the-box
TypeScript compilation. This is good! But it means we have to adapt some
of our existing TypeScript stuff.

As of this writing, Next.js enforces that the app directory contain its
own tsconfig.json file (vercel/next.js#7333), so this PR adds those as
necessary, inheriting from the parent package’s configuration. It also
requires a handful of specific configurations, so those are included as
well (vercel/next.js#7361) in those files.

This change also hoists acorn and acorn-dynamic-import because those two
packages need to be in a consistent place relative to each other and
webpack. (vercel/next.js#6240)

Currently the 'next' module does not export a type for its constructor
function, so we switch 'import next' to 'const next = require' to avoid
the typechecking.

We add "export {}" to the bottom of files that don’t do their own import
/ exporting to avoid an error due to the required "isolatedModules"
setting. (These can be removed if "isolatedModules" is removed.)

The bulk of the changes are updating _app and _document classes to the
nice new types.
@fionawhim
Copy link
Contributor Author

OK, this is the Next.js TypeScript update branch. It seems workingish as of the latest canary.

Unfortunately due to vercel/next.js#7361 our usages of ts-node may need to either change (maybe to babel-node?) or have their own tsconfig.json file that specifies a "commonjs" module type.

To update this to the latest canary, I think the easiest thing to do is delete the "next" entry from yarn.lock and then yarn install. You should also then comb through the yarn.lock and perhaps consolidate @babel/… entries.

Copy link
Contributor

@jessicamarcus jessicamarcus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants