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

False positive for @typescript-eslint/no-unnecessary-condition with export let #203

Open
kevincox opened this issue Mar 18, 2023 · 0 comments

Comments

@kevincox
Copy link

<script lang="ts">
	export let mode: "foo" | "bar" = "foo";
	mode == "foo";
</script>
src/Test.svelte
  3:2  warning  Unnecessary conditional, both sides of the expression are literal values  @typescript-eslint/no-unnecessary-condition

It seems like typescript doesn't realize that the prop is mutable.

The problem doesn't exist for various other ways of writing this:

export let mode = "foo" as "foo" | "bar";
export let mode = "foo";
export let mode: "foo" | "bar";

In all of these cases no warning is emitted.

This occurs for more than just union types. For example it also works with enums and booleans.


  • @typescript-eslint/eslint-plugin: 5.55.0
  • @typescript-eslint/parser: 5.55.0
  • eslint: 8.36.0
  • eslint-plugin-svelte3: 4.0.0
  • svelte: 3.57.0
  • typescript: 4.9.5
module.exports = {
	extends: [
		"eslint:recommended",
		"plugin:@typescript-eslint/strict",
	],
	parser: "@typescript-eslint/parser",
	parserOptions: {
		project: "tsconfig.json",
		extraFileExtensions: [".svelte"],
	},
	overrides: [{
		files: ["*.svelte"],
		processor: "svelte3/svelte3",
	}],
	plugins: [
		"@typescript-eslint",
		"svelte3",
	],
	settings: {
		"svelte3/typescript": true,
	},
};
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

1 participant