tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

Typescript checks ignoring undefined #197

Closed Coobaha closed 3 years ago

Coobaha commented 3 years ago

Hi @tomblachut ! Thanks for this awesome plugin! I've noticed that ts type checking is buggy with this snippet

<script lang="typescript">
  type Ctx = {
    ddd: void | string;
    dddd: undefined | string;
  };
  let test: string;
  export let ctx: Ctx;
  if (ctx) {
    test = ctx.dddd;
    test = ctx.ddd;
  }

</script>

image

Vscode

image

tomblachut commented 3 years ago

I don't understand, why do you think it's buggy?

Coobaha commented 3 years ago

For some reason it narrows down the type without undefined (and i believe nulls too).

notice that dddd can be undefined, but in .svelte files this weird narrowing happens and let test: string = ctx.dddd is valid in IDE

tomblachut commented 3 years ago

Ah I didn't spot two errors, thanks for clarification

tomblachut commented 3 years ago

Verified to work in v0.21.0 (Please make sure strictNullChecks are enabled.

image