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

Error referencing properties of destructured variables #2671

Open
jhwz opened this issue Jan 21, 2025 · 0 comments
Open

Error referencing properties of destructured variables #2671

jhwz opened this issue Jan 21, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@jhwz
Copy link

jhwz commented Jan 21, 2025

Describe the bug

Follow up to #2659

When referencing properties of destructured variables in a type, it will show the error Cannot find name '<variable>' in both svelte-check and the language server.

Workaround is to do (typeof <variable>)["<property>"] instead of typeof <variable>.<property>.

Reproduction

<script lang="ts">
	import type { PageData } from './$types.js';

	type Props = {
		data: PageData;
	};
	let { data }: Props = $props();

	type Fails = typeof data.cfg; // error here: Cannot find name 'data'
	type Okay = (typeof data)['cfg'];
</script>

Expected behaviour

Shouldn't throw a type error.

System Info

  • OS: MacOS
  • IDE: VSCode

Which package is the issue about?

svelte-language-server, svelte-check

Additional Information, eg. Screenshots

No response

@jhwz jhwz added the bug Something isn't working label Jan 21, 2025
@jhwz jhwz changed the title Error referencing properties of destructured properties Error referencing properties of destructured variables Jan 21, 2025
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

1 participant