Skip to content

Interface $$Events is labeled as unused but necessary for Typescript #843

Closed as not planned
@justingolden21

Description

@justingolden21

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?

^8.56.0

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

^2.35.1

What did you do?

Configuration
module.exports = {
	root: true,
	parser: '@typescript-eslint/parser',
	extends: [
		'eslint:recommended',
		'plugin:@typescript-eslint/recommended',
		'plugin:svelte/recommended',
		'prettier'
	],
	plugins: ['prettier', '@typescript-eslint'],
	ignorePatterns: ['*.cjs'],
	parserOptions: {
		sourceType: 'module',
		ecmaVersion: 2022
	},
	env: {
		browser: true,
		es2017: true,
		node: true
	},
	globals: {
		gtag: true,
		__version__: true
	},
	overrides: [
		{
			files: ['*.svelte'], // Apply these settings to Svelte files
			parser: 'svelte-eslint-parser', // Use the Svelte parser for .svelte files
			parserOptions: {
				parser: '@typescript-eslint/parser' // Use TypeScript parser for inside <script> blocks
			}
		}
	],
	rules: {
		'prettier/prettier': 'error',
		'quotes': ['warn', 'single', { avoidEscape: true }],
		'no-console': 'off',
		'no-tabs': 'off',
		'no-restricted-syntax': 'off',
		'func-names': 'off',
		'quote-props': ['error', 'consistent-as-needed'],
		'guard-for-in': 'off',
		'import/extensions': 'off',
		'new-cap': 'off',
		'import/no-extraneous-dependencies': 'off',
		'no-param-reassign': 'off',
		'radix': 'off',
		'@typescript-eslint/no-inferrable-types': 'off',
		'prefer-const': 'error',
		'svelte/no-at-html-tags': 'off',

		// Not designed to work with typescript; turned off in favor of typescript-eslint rules
		'no-undef': 'off',
		'no-unused-vars': 'off',

		// Unused vars must start with `_`
		'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],

		// TODO: remove below
		'@typescript-eslint/no-explicit-any': 'off',
		'@typescript-eslint/ban-ts-comment': 'off'
	}
};

<script lang="ts">
	import type { ChangeEventHandler } from 'svelte/elements';

	// Necessary because we forward the `on:change` event
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	interface $$Events {
		change: Parameters<ChangeEventHandler<HTMLInputElement>>[0];
	}
	export let checked: null | boolean = false;
	export let id: string;
	export let labelText: string;
</script>

<div>
	<div>
		<input bind:checked type="checkbox" {id} on:change />
		<label for={id} class="toggle-bg" />
	</div>
	<label for={id}>
		{labelText}
	</label>
</div>

What did you expect to happen?

This should not be an error since $$Events is necessary for on:change and otherwise I get errors from Typescript and when running check:

svelte-check --tsconfig ./tsconfig.json

Error: Property 'checked' does not exist on type 'EventTarget'. (ts)
                                on:change={(e) => {
                                        if (e.currentTarget.checked) {

What actually happened?

Toggle.svelte
5:12 error '$$Events' is defined but never used @typescript-eslint/no-unused-vars

Link to GitHub Repo with Minimal Reproducible Example

https://eslint-online-playground.netlify.app/#eNplU8tu2zAQ/JUFEcCX2OrZlY0AbYAUSIsCzS0KEFpc23QoUiUpx4Gqf+/yEdlKDnqQuzOc3R32zNm6wBNvWoULd0TlkS1Z6WorWw+Ka7FbVcy7iq0rDSCb1lgP3ux2CmFrTQOztMjg2ddKK/RQ77F+QQEr2HLlkHbLIpESDy0eIihSinBAWrKwsZFaLDN+1eefIUQU36B6wJNf9bNEMBugWLPrWMVEx7SIcw2WTvfvVby1CD1821MC3h5R+zuqV6GFIZeWuApU2FDUUXEBHzmKAn5hjc5x+wYbrHnnEF6pJ8a+civA7xGejaZCAvszYOAfobd/7qX2IAw6PfPwos0rIbgPDBqpb34vXeCKIlMhIxidIvBcSMc3CueaGjKnHYSbc/I8JRXazDtN0sT8yK3L5WuPdstrhKurWLaDPkUqn+Qu4Te3vEHKc+Xn/pR3Dz/vf+i287epM+v145en1Bw/pA+eYo8vvLAE3SkF/2BjjEKuz974CJCU67yVevc5NnpgknI2Vx5QKeQxT/vilxYyyJ54LLaYDBKXG3OqGPRSDDAOjyw2wuPxYTCrmPMeKYuL86Y5I7YfpecWlUXciQkXBPSQo9P8FrXRW7lbHBwZOtv2QMYI7qzYTR7ygaxNNyx3SeCWd8rDY7gyB5cp3MJibRqalkBxHUJ9eAHYTqFbvq8A/nbGh43HiqG1xlbsmo4SpiOvVewpQgGG+A1vmnvQ2/L6he+QlBpNWiMdXTpqbcWW9NcYQQcRWQoIPH7HNojRtUTSPyqYlhWgipMgn6EhIcWnwSin0gMb/gOIOLht

Additional comments

Thank you in advance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions