TypeScript: Newly created files don't belong to typescript project on MacOS
Bug Report
π Search Terms
Maybe ts, vscode, file is not part of ts project, newly created?
π Version & Regression Information
Tested on the following typescript versions:
- 4.5.0-dev.20210904
- 4.4.2
- 4.4.1-rc
- 4.3.5
vscode version: 1.60.0
β― Playground Link
https://github.com/yifanwww/ts-bug-repo
This is a very simple projectβ¦
π Actual behavior
Open that project via vscode(whatever open folder directly or open the workspace file).
Open the file src/index.ts to get tsserver started, then create a new file src/test.ts.
There should be an error cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.ts(1208), but actually it got no error.
Execute vscode command Typescript: Go to Project Configuration, a panel appears with info File is not part of a Typescript project. Click here to learn more.
In that new ts file, no auto-completion and no auto-import to use the function fn which is declared in src/index.ts.
I have to restart tsserver or reload vscode.
I have checked these issues but still donβt know how to solve this problem.
- https://github.com/microsoft/TypeScript/issues/43290
- https://github.com/microsoft/TypeScript/issues/36532
- https://github.com/microsoft/TypeScript/issues/35794
- https://github.com/microsoft/TypeScript/issues/33564
This bug never happens on my win laptop, but does always happen on my mac laptop.
π Expected behavior
The file gets added into the existing typescript project.
BTW, If you need tsserver.log, please tell me how to get it.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 19 (7 by maintainers)
Commits related to this issue
- [tsconfig.json] Use wildcard paths to include all TS/JS files in the source folders. This ensures that VSCode recognizes new files, indexes them, and allows e.g. ESLint to recognize them. Workaround ... — committed to cubing/cubing.js by lgarron 3 years ago
- [tsconfig.json] Use wildcard paths to include all TS/JS files in the source folders. This ensures that VSCode recognizes new files, indexes them, and allows e.g. ESLint to recognize them. Workaround... — committed to cubing/cubing.js by lgarron 3 years ago
- [tconfig.json] Remove workarounds for picking up new TS files in VSCode. See https://github.com/microsoft/TypeScript/issues/45721 — committed to cubing/cubing.js by lgarron 2 years ago
Hello, I have exactly same issue but on Linux, but i have found the problem and an temporary solution.
The problem come from
includeproperty intsconfig.jsonwhen that property is set to folder or too ambigu in that casesrc(but this is same if is set tosrc/**/*). My solution its stupid but simply specify file typesrc/**/*.ts.Thanks.
Iβm also seeing the same issue for the last fewβ¦ weeks?
Itβs especially annoying during branch switches, because any files that were moved/created/deleted between the branches will be subject to this bug.
Thanks, this trick saved me a lot of time! If anyone is trying this workaround, I recommend restarting VSCode rather than just restarting the TypeScript server. That helped it stick for me.
@orblazer Thanks a lot, seems this temporary solution works for me.