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

Fix TypeScript type-checking: Set "target": "esnext" in the default tsconfig.json #5772

Closed

Conversation

ndbroadbent
Copy link

@ndbroadbent ndbroadbent commented Nov 11, 2018

This fixes the issue that I just experienced while trying to figure out a TypeScript type error: #5771

The CRA webpack config includes polyfills for IE9+, so the TypeScript type checker should be using the type definitions for the latest JS features, including Array.includes, Object.assign, etc. The current default tsconfig.json limits TypeScript to only using ES5 features.

Note that the Babel compilation doesn't actually care about tsconfig.json, and this doesn't affect any emitted JavaScript, because CRA isn't using TypeScript to compile the JS. It only affects type-checking, because TypeScript infers the type declarations from the "target". (Type declarations can also be overriden by setting the "lib" option.)

I've confirmed that the new default tsconfig.json has the updated target, and that yarn start and yarn build are both running fine after this change.

UPDATE: Actually I just did some research to find out what Babel supports, and I think it would be better to use ES2018 here, because Babel definitely supports ES2018. And actually it's better to leave the target as "es5", and just add the "lib" option.

UPDATE 2: Haha NOOOOOOOOO, this was already fixed but wasn't released yet! Oh well!

…ig includes polyfills for IE9+, so TypeScript should use the type definitions for the latest JS features
@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@ndbroadbent ndbroadbent changed the title Set "target": "esnext" in the default tsconfig.json. Set "target": "esnext" in the default tsconfig.json Nov 11, 2018
@ndbroadbent ndbroadbent changed the title Set "target": "esnext" in the default tsconfig.json Fix TypeScript type-checking: Set "target": "esnext" in the default tsconfig.json Nov 11, 2018
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants