microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.07k stars 29.21k forks source link

VSCode 1.44.2 no longer showing all TypeScript errors #95624

Closed doberkofler closed 4 years ago

doberkofler commented 4 years ago

Steps to Reproduce:

It seems as if after upgrading to VSCode 1.44.2 I no longer see (all) TypeScript errors in VSCode. There is a typing problem in my code that when russing tsc is reported as error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'valuesExternalType' but the error is not shown in VSCode. Other problems are shown. Additionally when looking at the Log (Extension Host) panel I see the following error:

[2020-04-19 08:13:25.404] [exthost] [info] ExtensionService#loadCommonJSModule file:///c:/Users/doberkofler.LBITS/AppData/Local/Programs/Microsoft VS Code/resources/app/extensions/npm/dist/main
[2020-04-19 08:13:25.753] [exthost] [info] eager extensions activated
[2020-04-19 08:16:00.864] [exthost] [error] [vscode.typescript-language-features] provider FAILED
[2020-04-19 08:16:00.865] [exthost] [error] Error: busy
    at a._provideSemanticTokens (c:\Users\doberkofler.LBITS\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:183890)

Does this issue occur when all extensions are disabled?: Yes

mjbvz commented 4 years ago

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

doberkofler commented 4 years ago

@mjbvz I've installed the latest insider build without any extensions and have the same (wrong) results.

I have also double checked if some other changes in my environment might cause this problem, but have not found anything.

The only additional clues is as follows: It seems af if errors related to and and null type mismatches would not been reported and when inspecting the types in VS Code, the types are sometimes wrongly shown.

The following code snippet for example:

function findRowByCellContent(): Promise<number|null> {...}

let rowIndex = 0;
const index = await findRowByCellContent();
rowIndex = index;

reports the error error TS2322: Type 'number | null' is not assignable to type 'number' in the linerowIndex = index; when compiled with tsc because the function findRowByCellContent as defined to return number|null.

In VS Code no error is reported and when hoovering over index and findRowByCellContent the following is shown: index -> const index: number findRowByCellContent -> findRowByCellContent: Promise<number>

mjbvz commented 4 years ago

Does your tsconfig use strict null checks?

Where is path of tsconfig and what is the path of the example TS file? I bet VS Code is not including the file in the tsconfig project

doberkofler commented 4 years ago

Thank you for your help!

Does your tsconfig use strict null checks?

Yes, I use strict null checks in my tsconfig.

Where is path of tsconfig and what is the path of the example TS file?

I'm not sure I understand your question and my environment is a bit complicated but I try to explain as good as possible.

I use 2 separate configuration files. One for the frontend code ./tsconfig.json and one for the Node.js based selenium tests tsconfig.selenium.json and both files include a base configuration file ./configs/tsconfig_base. The sources for the front end are in a ./src directory and the ones for the selenium tests in a ./test/selenium directory. I'm currently only experiencing problems in the ./test/selenium directory. I'm not aware to explicitly include any tsconfig file in my VS Code settings.

./tsconfig.json:

{
  "extends": "./configs/tsconfig_base",
  "compilerOptions": {
    "paths": {
    }
  },
  "compileOnSave": false,
  "include": [
    "src/**/*",
    "test/unittest/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

./tsconfig.selenium.json:

{
  "extends": "./configs/tsconfig_base",
  "compilerOptions": {
    "noImplicitThis": true,
    "noEmit": false,
    "target": "es2018",
    "module": "commonjs"
  },
  "compileOnSave": false,
  "include": [
    "test/selenium/**/*",
  ],
  "exclude": [
    "node_modules"
  ]
}

./configs/tsconfig_base:

{
  "compilerOptions": {
    "skipLibCheck": true,
    "extendedDiagnostics": false,
    "noEmit": true,
    "downlevelIteration": true,
    "allowJs": true,
    "checkJs": false,
    "sourceMap": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": false,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "esModuleInterop": true,
    "declaration": false,
    "importHelpers": true,
    "moduleResolution": "node",
    "target": "es2015",
    "module": "esnext",
    "jsx": "react",
    "baseUrl": "../",
    "outDir": "../temp",
    "lib": [
      "es2017",
      "dom"
    ]
  }
}
doberkofler commented 4 years ago

I forgot to add that when checking my sources manually from the terminal I use the following command: npx tsc --noEmit --project ./tsconfig.json && tsc --noEmit --project ./tsconfig.selenium.json

mjbvz commented 4 years ago

Thanks for the details.

This is the expected behavior for your setup. VS Code's IntelliSense only loads projects from files named tsconfig.json. This means it will not load ./tsconfig.selenium.json as a project and the files under test will not considered as belonging to any project. You can confirm this by running TypeScript: Go to project configuration in one of the TypeScirpt files under test

https://github.com/microsoft/TypeScript/issues/33094 would improve this. Until then, you'll need to make sure you use files called tsconfig.json to define your projects if you want proper IntelliSense (these tsconfig files can extend other tsconfigs that are not named tsconfig.json)

doberkofler commented 4 years ago

Thank you for all the help. I'm still puzzled why it seems to have worked earlier, but I'm sure I just miss some change in the environment. I'm still not sure on how to solve or work around this problem. The frontend files require a different tsconfig than the node.js files when being compiled, so I must include different directories. Could you be so kind and point me to the right direction on what to do?

mjbvz commented 4 years ago

The VS Code behavior has not changed recently but something about your project structure may have changed. Two quick ways you could look into that should support intellisense:

Or:

doberkofler commented 4 years ago

Thank you for explaining and two more short questions just to make sure:

I guess your first option would not work in my setup because build the project and building the tests requires different TypeScript setting. Correct?

The second option looks great and implies that VS Code is able to find/use tsconfig.json in subdirectories when started in the root. Correct?

mjbvz commented 4 years ago

Yes, it picks up tsconfigs in subdirectories so long as they are named tsconfig.json

doberkofler commented 4 years ago

Thank you! This works like a charm and I completely missed it. Is this documented somewhere as it might really help others?