Typescript: Having both a .ts and .js file with the same name breaks intellisense

Created on 9 Oct 2020  路  6Comments  路  Source: microsoft/TypeScript

Having e.g. test.js and test.ts in the same project partially breaks intellisense.

Expected behavior:

Since value might be _undefined_ , I would expect an error - just like we get when there is no test.ts present.

image

Actual behavior:

Notice how test.ts is now present (it's just an empty file), and we no longer receive an error - but the intellisense partially works, as the tool tip reveals the type of value.

image

Notice how it no longer knows that value might be _undefined_. It's like the validation rules for .ts files are being used for .js files all of a sudden.

If we rename _test.ts_ to _test2.ts_, then intellisense works again.

image

Content of jsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "checkJs": true,
        "resolveJsonModule": true,
        "strictNullChecks": true,
        "noImplicitAny": true
    }
}

Tested with TypeScript 4.0.3 and TypeScript@Next (4.1.0-dev.20201009).

VSCode:

Version: 1.50.0
Commit: 93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
Date: 2020-10-07T06:00:00.397Z (2 days ago)
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 17.7.0

Working as Intended

Most helpful comment

Most likely the same issue as #40982.

All 6 comments

Most likely the same issue as #40982.

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@andrewbranch , is this really the desired behaviour? I'm sure the code does what it's supposed to do. But the behaviour still makes no sense and can easily confuse developers.

If anything, we should probably give you a configuration error in this case. Since jsconfig.json has noEmit: false by default, the existence of a JS file and TS file by the same basename looks highly suspicious. The assumption made by the config parser is that the TypeScript file is the canonical source, and the JS can be ignored since it is assumed to be the emit output. But that assumption itself is pretty suspicious, since noEmit is false, and if it were true, JS files that _don鈥檛_ have a corresponding TS file by the same basename would be an error. So there鈥檚 really no way to interpret this situation that doesn鈥檛 look like a misconfiguration.

This is somewhat similar to #40195

Okay, I see. That makes sense. I appreciate the elaboration - thank you :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonathandturner picture jonathandturner  路  147Comments

rbuckton picture rbuckton  路  139Comments

born2net picture born2net  路  150Comments

disshishkov picture disshishkov  路  224Comments

rwyborn picture rwyborn  路  210Comments