Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No null and undefined type checking errors #1820

Open
3 tasks done
danielvy opened this issue Apr 1, 2020 · 2 comments
Open
3 tasks done

No null and undefined type checking errors #1820

danielvy opened this issue Apr 1, 2020 · 2 comments

Comments

@danielvy
Copy link

danielvy commented Apr 1, 2020

  • I have searched through existing issues
  • I have read through docs
  • 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.

@octref
Copy link
Member

octref commented Jun 7, 2020

<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

@klesun
Copy link

klesun commented Nov 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants