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

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

Open
marekdedic opened this issue Nov 7, 2024 · 2 comments
Open

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

marekdedic opened this issue Nov 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@marekdedic
Copy link

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

  • OS: Debian testing

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.

@marekdedic marekdedic added the bug Something isn't working label Nov 7, 2024
@brunnerh
Copy link
Member

brunnerh commented Nov 8, 2024

Related to/essentially duplicate of:

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

@marekdedic
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants