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

Use "target": "es6" in default tsconfig.json, because create-react-app includes polyfills for IE9+ #2

Closed
wants to merge 1 commit into from

Conversation

ndbroadbent
Copy link

@ndbroadbent ndbroadbent commented Nov 11, 2018

Here's the issue I just experienced with create-react-app: facebook/create-react-app#5771

To summarize: TypeScript was giving me type errors because I wanted to use ES6 functions like Array.fill and Object.assign. I discovered that create-react-app uses Babel for all of the JS compilation, and they just strip the types. They use this package to do type-checking in a separate process. They also already include polyfills to support IE9+, so it's fine to use the "es6" target in the default tsconfig.json (which tells TypeScript to use ES6 type definitions.)

…es polyfills for IE9+, so TypeScript should use these ES6 type definitions
@johnnyreilly
Copy link

johnnyreilly commented Nov 11, 2018

Hey @ndbroadbent

I don't think this change should be applied to the checker. It should apply to the tsconfig.json in the project using the checker.

Remember the checker is written in TypeScript; the change here would just change how the checker js was emitted for use by webpack. i.e. It shouldn't have any bearing on the issue you're facing.

@johnnyreilly
Copy link

It's probably worth making this change in the tsconfig.json in create-react-app itself. Question: what transpilation does Babel do in CRA? ES2015 -> es5? ES2018-> es5? So many possibilities!

@ndbroadbent
Copy link
Author

ndbroadbent commented Nov 11, 2018

Hi @johnnyreilly, ok thanks! I'm trying to think how to do that. What do you think about a new defaultCompilerOptions option for ForkTsCheckerWebpackPlugin? It would be cool if create-react-app could call something like this in their webpack config:

new ForkTsCheckerWebpackPlugin({
  defaultCompilerOptions: {
    "target": "es6",
  },
  // ...
})

Then fork-ts-checker-webpack-plugin could merge that object with the compilerOptions from the default tsconfig.json in this repo before saving it. It would also let them configure any other default settings while they continue to improve the TypeScript integration.

@ndbroadbent
Copy link
Author

ndbroadbent commented Nov 11, 2018

Whoops, sorry, I got confused! I had opened this file from react-scripts in the wrong editor window and I thought it belonged to fork-ts-checker-webpack-plugin. I was really struggling to find their default tsconfig.json, but I realized they're dynamically generating it from the compilerOptions with some suggested values.

Anyway, sorry to bother you!

@ndbroadbent
Copy link
Author

ndbroadbent commented Nov 11, 2018

Question: what transpilation does Babel do in CRA? ES2015 -> es5? ES2018-> es5? So many possibilities!

Sorry, forgot to reply! They support the latest stable ES features from @babel/preset-env, which includes ES2018, but I'm not sure about things in ESNext. And they include a polyfill to support IE9. And yes I think they are emitting ES5 for browser compatibility.

@johnnyreilly
Copy link

They support the latest stable ES features from @babel/preset-env

Probably worth using "target": "ESNext" then?

https://www.typescriptlang.org/docs/handbook/compiler-options.html

@ndbroadbent
Copy link
Author

Haha NOOOOOOO someone already fixed this 9 days ago to use "esnext", but they didn't release that change yet. Haha that's so frustrating: facebook/create-react-app#5684

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