-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Automatically generate and validate tsconfig.json
#5508
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
Comments
I can take this on @Timer. A few thoughts: We could publish the What do you think? EDIT: Sorry i think GitHub is having issues. I didn't think my original comments got posted. I deleted them in place of this one. |
Hey @ianschmitz I never saw this comment until now since GH was having issues all evening 😅. I believe we overlapped on some work -- let's see what we can do about incorporating changes from both of them. |
No worries. What are your thoughts on the @types package? |
I'm not sure that's the best thing to do, it's very common to not be on the latest Alternatively, can we add an entry to tsconfig that references something like |
Yeah that would work. I was initially thinking that we could have a dependency in However your idea would probably keep things simpler and be one less package to manage. It just means a little less benefit for non TypeScript users. |
What do you mean by this? |
I think VS Code by default will pick up types in your |
Why was this decision made? The overwriting of my tsconfig is causing There should be a way to opt out of this behavior without ejecting. Seems pretty overzealous |
@ArcticZeroo can you please share your full |
Sure, {
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"lib": [ "es2018", "dom" ],
"jsx": "react",
"downlevelIteration": true,
"noImplicitAny": true,
"esModuleInterop": true
},
"exclude": [
"node_modules"
]
} Here's the one react-scripts really wants me to use for some reason (this one does literally nothing when I type {
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"lib": [
"es2018",
"dom"
],
"jsx": "preserve",
"downlevelIteration": true,
"noImplicitAny": true,
"esModuleInterop": true,
"allowJs": true,
"skipLibCheck": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": [
"node_modules"
],
"include": [
"src"
]
} And this one actually does try to compile the files, but completely ignores all my custom types in {
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"lib": [
"es2018",
"dom"
],
"jsx": "preserve",
"downlevelIteration": true,
"noImplicitAny": true,
"esModuleInterop": true,
"allowJs": true,
"skipLibCheck": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": [
"node_modules"
],
"include": [
"./src/*"
]
} |
Would it just be possible to disable React's TS support for 2.x? I can (and would prefer to) compile the files myself instead |
It appears that |
That seems really weird to be a default for setting up TS 😕 I definitely didn't set that one. Is there any reason that Now it's complaining about ordering of imports...
It's not really something I can control since the TS compiler is moving the import down... |
Been looking into it more and I still don't understand the decisions behind most of these config changes. With webpack (plus the fact that TS can change import to require) there's no reason to make the module type esnext, it can easily be es2015 (and then it passes the unnecessary ESLint checks). It also doesn't make any sense to have noEmit set to true (when I set it to false it goes back to true!) since completely restarting the react app still doesn't cause create-react-app to recompile the TS, so if I have to compile it myself why would it be disabled? This seems silly. |
We don't support you having TypeScript files side-by-side to JavaScript files. You either need to let Create React App compile TypeScript itself, or move your project files to a different folder. |
I assumed that was the case, so I deleted all the .js, .jsx, etc files from the src/ folder (so I ONLY had typescript) but it was complaining about missing |
@ArcticZeroo please delete all JavaScript files in Next, cancel your dev server and update your Start your dev server again, did that work? |
@Timer a tentative yes, it seems like it is working now! I'm not sure why it was expecting JS before since I have no other JS at all in my project and it was giving Typescript errors as well. Thanks! I promise I wasn't trying to be difficult here, just trying to get my project building :) |
No worries, if this is something we can improve in our docs that'd be great! |
Yeah, that would definitely be nice. Unless I am just bad at googling, I couldn't actually find any information at all about TS support in React aside from the blog post (and ended up just having to find relevant commits to adding the TS support to figure out what's going on) -- is there any kind of doc about it to start on? I'd be willing to write something up to go over the issues I faced migrating from 1.x to 2.1.x :) |
There's no documentation right now except "Adding TypeScript" -- if you could propose something that'd be great, we're open to hearing any feedback. |
When using TypeScript, we should automatically generate and validate
tsconfig.json
.isolatedModules: true
.d.ts
files from templateThe text was updated successfully, but these errors were encountered: