Skip to content

Union types for props cause trigger of svelte/no-unused-props #1168

@WarningImHack3r

Description

@WarningImHack3r

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.23.0

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

3.4.0

What did you do?

Configuration
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import svelte from "eslint-plugin-svelte";
import prettierConfig from "eslint-config-prettier/flat";
import globals from "globals";
import svelteConfig from "./svelte.config.js";

export default tseslint.config(
	eslint.configs.recommended,
	tseslint.configs.recommended,
	svelte.configs.recommended,
	prettierConfig,
	svelte.configs.prettier,
	{
		languageOptions: {
			globals: {
				...globals.browser,
				...globals.node
			}
		}
	},
	{
		files: ["**/*.svelte", "**/*.svelte.js", "**/*.svelte.ts"],
		languageOptions: {
			parserOptions: {
				parser: tseslint.parser,
				extraFileExtensions: [".svelte"],
				projectService: true,
				svelteConfig
			}
		}
	},
	{
		rules: {
			"@typescript-eslint/no-unused-vars": ["error", { ignoreRestSiblings: true }]
		}
	},
	{
		ignores: ["build/", ".svelte-kit/", "dist/", "src/lib/components/ui/", "src/lib/utils.[jt]s"]
	}
);
<script lang="ts">
	type MyType = { thing: string };
	type Props = {
		myProp: { a: string } & MyType;
	};
	let { myProp }: Props = $props();
</script>

{myProp.thing}

If I don't use myProp.a in my code, even if I use one or more properties of MyType, a is marked as unused props

What did you expect to happen?

Not having this reported because I do use myProp

What actually happened?

Got this error reported on my $props()

Link to GitHub Repo with Minimal Reproducible Example

https://eslint-online-playground.netlify.app/#eNqFVE1v2zAM/SuCMAxdENv3rB0KdNut2LDtVuXg2IynVJYMSU4TBP7vpT7sOHGSnmSTj+R7FMUDNbrInvdPqm6UBGlTswVhgS7ovSk0bywRuaweGLWG0W9MMmv3DZDn/T93PJADsf+5rBbEWI0n6b4OmN9aNcZBnIXZeu8MC4zIj2jyOabyYSFYgEVQgJNuMeT51LiPuy8Ius8COUdIHgI09UQ6JumcghEctRRKrnmVbgzK4ShQWxI8ZK1VTRh9DL/ZBsVh2oix5hTl1IR6SXCMwaFfPTT4k0a0FZdJ8I3RjQZrOegnz+wsKtBNeky2FvlJqUqoVS5MHxV/PYJJ2HlMCeu8FUcNsQd3rrEnFpNqKFRdgyyhnPtLOw2ZAoKcq+5TbZcieoT3xbFw49XmFfxqLFfS4HwEO7NR38jCbJqm0ZyutHozMdfEKVUJvQNHYji6cek1F4DpXxidzbJZnHxG59jbkQHHZ2pzr2EZS19X0OQaGU7tvWdxvKZgGImBndX5T2T4Y2dBmpABqQ40lx/q063XdyxLHyejnEmVtLI1UCZbpMCoLwJaK+1UHwivpNLwB4z9y1cYUWFGzAykiwSmdUNIoLtquSiz0MBIPXnlNlpKbvpPt4cEX2U4U2ETmazlZ77Wcrzbl41duvb7uky6fYBPvsmLV7wEvC0l8bkjFRKfrtPEaK1KbAfmC44Stt+hccMrCw5etw9xvvFWcKH4DFF+DHWAfgvccJ4/5tvgs31xETo894vem6Gx730xP2pXoMcB+RAwLMMxzsHwUtwa7t4BzLVIRw== (can't make typescript work)

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions