Skip to content

Error referencing properties of destructured variables #2671

@jhwz

Description

@jhwz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy