Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

False positive TypeScript ESLint errors when using slot props #394

Open
@rowanlovejoy

Description

@rowanlovejoy

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

  • I'm usingeslint-plugin-svelte. (*.svelte file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue ineslint-plugin-svelte repo and open the issue ineslint-plugin-svelte repo if there is no solution.
  • 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.47.0

What version ofeslint-plugin-svelte and svelte-eslint-parser are you using?

  • svelte-eslint-parser@0.32.2
  • eslint-plugin-svelte@2.32.4

What did you do?

Configuration

module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:svelte/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
extraFileExtensions: ['.svelte'],
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
},
},
],
root: true,
env: {
browser: true,
node: true,
},
};

// App.svelte<scriptlang="ts">importCustomListfrom'./lib/CustomList.svelte';importtype {ListItem }from'./lib/types';const items:ListItem[]= [{title:'Svelte.dev',link:'https://svelte.dev',},{title:'TypeScript ESLint',link:'https://typescript-eslint.io',},{title:'TypeScript',link:'https://www.typescriptlang.org',},];const openLink= (item:ListItem)=> {window.location.replace(item.link);};</script><main><CustomList{items}let:item><div>{item.title}<buttonon:click={()=> {openLink(item);}}>Open Link</button></div></CustomList></main>// CustomList.svelte<scriptlang="ts">importtype {ListItem }from'./types';exportlet items:ListItem[];</script><div><ul>{#eachitemsasitem(item.title)}<li><slot {item} /></li>{/each}</ul></div>
// types.tsexportinterfaceListItem{title:string;link:string;}

What did you expect to happen?

No ESLint errors or warnings are raised for the code, as the types are defined and compatible with how they are being used.

What actually happened?

ESLint raises two errors. The first,@typescript-eslint/no-unsafe-member-access, when accessing thetitle property of theitem slot prop; the second,@typescript-eslint/no-unsafe-argument, passing theitem slot prop to theopenLink function.

Link toGitHub Repo with Minimal Reproducible Example

https://github.com/rowanlovejoy/eslint-svelte-test

Additional comments

The minimal reproduction repo is based on the Vite Svelte template described here:https://vitejs.dev/guide/#scaffolding-your-first-vite-project It includes additionalpackage.json commands to run ESLint and the TypeScript compiler independently. It uses PNPM.

The template code of theApp.svelte component demonstrates the linting error.

The app renders a list of items. Each item includes a title and a link. For each item, the title is rendered along with a button to open that link in the current browser tab.

I believe this is a parsing problem because this issue occurs only on the template (which I understand the parser transforms into an AST; apologies if this is incorrect, I've never worked on anything like this); the TypeScript compiler correctly understands the code; the errors being raised are noteslint-plugin-svelte ruleset; and I've used this same configuration in React TypeScript projects with almost identical code and not experienced similar problems.

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp