sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.26k stars 200 forks source link

[svelte-check] TS error when deriving from value #2573

Open marekdedic opened 2 weeks ago

marekdedic commented 2 weeks ago

Describe the bug

Hi, I'm getting an error when deriving from a value caused by the fact that at the point the derived rune is used, the original variable has a fixed value:

Reproduction

<script lang="ts">
  let one: Array<number> | null = $state(null);
  let two = $derived(
    one === null ? 42 : one.find((x) => x > 22)
  );
</script>

I get Error: Property 'find' does not exist on type 'never'.

Expected behaviour

No error

System Info

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

https://svelte.dev/playground/feba78a349b34e49aedc626604866047?version=5.1.12

Looking at the JS output, the error makes sense.

In my actual usecase, I'm binding the variable one.

brunnerh commented 2 weeks ago

Related to/essentially duplicate of:

(That issue still should be moved somewhere that isn't the SvelteKit repository.)

marekdedic commented 2 weeks ago

Yeah it is, sorry, didn't find it... So, should I close this? Or is the actual issue here in svelte2tsx?