Skip to content

false positive @typescript-eslint/no-unsafe-assignment when deriving prop type from ComponentProps #1303

@Theo-Steiner

Description

@Theo-Steiner

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

9.34.0

What version of eslint-plugin-svelte are you using?

3.11.0

What did you do?

Configuration
import js from "@eslint/js";
import sveltePlugin from "eslint-plugin-svelte";
import tseslint from "typescript-eslint";
export default tseslint.config(
  js.configs.recommended,
  ...tseslint.configs.recommended,
  ...sveltePlugin.configs["flat/recommended"],
  {
    files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
    languageOptions: {
      parserOptions: {
        parser: tseslint.parser,
        extraFileExtensions: [".svelte"],
        projectService: true
      },
    }
  },
  {
  	rules: {
			'@typescript-eslint/no-unsafe-assignment': 'error',
		}
  }
);

ComponentA.svelte

<script lang="ts">
    let {a}: {a: number} = $props();
</script>

<p>{a}</p>

MyComponent.svelte ← error occurs here

<script lang="ts">
    import type { ComponentProps } from 'svelte';

    import ComponentA from './ComponentA.svelte'

    interface Props {
        a: ComponentProps<typeof ComponentA>['a']
    }

    let { a }: Props = $props()
</script>

<ComponentA {a} />

What did you expect to happen?

a should be inferred correctly as number based on the typings of ComponentA

What actually happened?

The other component's prop instead is inferred as any: Unsafe object destructuring of a property with an any value.

Link to GitHub Repo with Minimal Reproducible Example

Playground

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions