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

Type casting inside reactive blocks causes errors #11527

Open
bennymi opened this issue May 9, 2024 · 1 comment
Open

Type casting inside reactive blocks causes errors #11527

bennymi opened this issue May 9, 2024 · 1 comment
Milestone

Comments

@bennymi
Copy link
Contributor

bennymi commented May 9, 2024

Describe the bug

Adding type casting inside a reactive block causes an error. This worked in Svelte 4.

<script lang="ts">

	let anchorEls: HTMLAnchorElement[] = [];

	$: {
		anchorEls = <HTMLAnchorElement[]>Array.from(document.querySelectorAll('a'));
	}
</script>

<a href="#1">1</a>
<a href="#2">2</a>

Reproduction

Svelte 5 Repl

Logs

No response

System Info

-

Severity

annoyance

@dummdidumm
Copy link
Member

simpler reproduction. Seems the cast is treated as JSX, wondering if there's an option in the Acorn TS plugin to not do that.
Either way, it's best to use as type casts instead, i.e. do

	$: {
		anchorEls = Array.from(document.querySelectorAll('a')) as HTMLAnchorElement[];
	}

instead

@dummdidumm dummdidumm added this to the 5.x milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants