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.

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

Most upvoted comments

Hello, I have exactly same issue but on Linux, but i have found the problem and an temporary solution.

The problem come from include property in tsconfig.json when that property is set to folder or too ambigu in that case src(but this is same if is set to src/**/*). My solution its stupid but simply specify file type src/**/*.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.

My solution its stupid but simply specify file type src/**/*.ts.

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.