Closed doberkofler closed 4 years ago
Does this reproduce in the latest VS Code insiders build with all extensions disabled?
@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>
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
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"
]
}
}
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
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
)
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?
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:
tsconfig.json
— Generic tsconfig used for editor, should include all TS files (both test and project files)configs/tsconfig_base
— Same as todaytsconfig.source.json
— Used to compile projecttsconfig.selenium.json
— Used to compile testsOr:
configs/tsconfig_base
— Same as todaysrc/tsconfig.json
— Used for projecttest/tsconfig.json
— Used for tests (may require a reference to the files under src
)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?
Yes, it picks up tsconfigs in subdirectories so long as they are named tsconfig.json
Thank you! This works like a charm and I completely missed it. Is this documented somewhere as it might really help others?
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 theLog (Extension Host)
panel I see the following error:Does this issue occur when all extensions are disabled?: Yes