vetur icon indicating copy to clipboard operation
vetur copied to clipboard

No null and undefined type checking errors

Open danielvy opened this issue 4 years ago • 2 comments

  • [X] I have searched through existing issues
  • [X] I have read through docs
  • [X] I have read FAQ

Info

  • Platform: MacOS 10.14.6
  • Vetur version: 0.24.0
  • VS Code version: 1.43.2

Problem

Vetur ignores null and undefined type checking in VSCode with strict null checking enabled in tsconfig (tried with both strict: true and strictNullChecks: true).

Reproduced with minimal .vue file:

<script lang="ts">
function test(): string {
	return;
}
const x: string = null;
const y = test();
</script>

The above code should report errors for return intest() function and assignment of null to x, but it doesn't.

Same code in .ts file in the same directory reports errors correctly. Transpiling the code (rollup + typescript plugin + vue plugin) fails due to errors as expected.

danielvy avatar Apr 01 '20 12:04 danielvy

  • Clone https://github.com/octref/veturpack
  • Replace counter.vue with below:
<template>
  <div></div>
</template>

<script lang="ts">
function test(): string {
	return
}
const x: string = null;
const y = test();
</script>

I do see errors being reported:

image

octref avatar Jun 07 '20 08:06 octref

Not sure if that was the case in OP's case, but in my case the problem is caused by having multiple tsconfig.json files in the project. The vetur seems to prefer the tsconfig.json located in the root of the project over the tsconfig.json located in a particular directory where the component resides.

So we have such tsconfig.json file in the project root:

{ "compilerOptions": { "strict": false } }

And such tsconfig.json file in the /src/strictly-typed/:

{ "compilerOptions": { "strict": true } }

Normal /src/strictly-typed/Something.ts files favour the nearest /src/strictly-typed/tsconfig.json file and have the strict typing, but the code in <script lang="ts"> of /src/strictly-typed/Something.vue files seems to pick up the root one sadly.

If I remove the root tsconfig.json, the strict typing gets picked up from the /src/strictly-typed/tsconfig.json ok and I do get my null checks.

klesun avatar Nov 19 '21 15:11 klesun