How to disable auto-recognition of .js files as TypeScript compilation output in IntelliJ IDEA

已回答

I'm using the latest version of IntelliJ IDEA and working on a project that uses both JavaScript and TypeScript. I'm facing an issue where IntelliJ automatically recognizes .js files as compiled output of .ts files when they have the same name.

What is the current method to disable the automatic recognition of .js files as TypeScript compilation output in the latest version of IntelliJ IDEA?

Example: Let's say I have the following files in my project: 

src/ 

── example.ts 

└── example.js

When I open example.js, I see a message at the top of the file saying "Excluded from compilation". This indicates that IntelliJ IDEA is treating this .js file as a compilation output of the .ts file, which is not what I want.

What I want to achieve: I want IntelliJ IDEA to treat both .ts and .js files as separate, editable source files, without automatically assuming the .js file is a compiled output.

 

Is there a way to do this?

0

The .js files with names matching .ts files are treated as generated and auto-excluded from indexing for better performance and navigation by adding them to exactExcludedFiles list in workspace.xml
If you like them to be included, please try adding <option name="excludeGeneratedFiles" value="false" /> to your project .idea/workspace.xml:
 
 

  • Close the project, shut down the IDE
  • Open .idea/workspace.xml
  • Replace <component name="TypeScriptGeneratedFilesManager"> section with the lines below:
<component name="TypeScriptGeneratedFilesManager">
   <option name="version" value="1" />
   <option name="excludeGeneratedFiles" value="false" />
   <option name="exactExcludedFiles">
     <list>
     </list>
   </option>
 </component>
  • Re-open project

 
Hope it helps

0

Elena Pogorelova 

Thank you very much. As you suggested, changing the settings resolved the issue!

However, in the IntelliJ directory UI, the UI that folds under the ts folder as a subfolder is still functioning. Is there a way to modify this setting as well? I'd like to treat them as completely separate files.

0

You can try modifying the file nesting rules accordingly.

1

Elena Pogorelova  Thank you very much, it's been resolved!

0

请先登录再写评论。