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

JSDoc types are lost in svelte files (typescript-eslint) #533

Open
Labels
@falco467

Description

@falco467

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?

9.3.0

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

  • svelte-eslint-parser@0.36.0
  • eslint-plugin-svelte@2.39.0

What did you do?

Configuration
import tsEslint from 'typescript-eslint'import epSvelte from 'eslint-plugin-svelte'import svelteParser from 'svelte-eslint-parser'export default [  ...tsEslint.configs.strictTypeChecked,  ...epSvelte.configs['flat/recommended'],  {    languageOptions: {      parser: tsEslint.parser,      parserOptions: {        project: true,        programs: false,        extraFileExtensions: ['.svelte']      },    },  },  {    files: ['**/*.svelte'],    languageOptions: {      parser: svelteParser,      parserOptions: {        parser: tsEslint.parser,      }    },  },]
<script>/**@param{number}x*/functiontest(x) {return x+1  }</script>

While both .svelte and .js files are scanned by ESLint the same function yields different results:

// test.svelte<script>/**@param{number}x*/functiontest(x) {return x+1  }</script>
// test.js/**@param {number} x */functiontest(x){returnx+1}

npx eslint src

test.js   2:10  error  'test' is defined but never used     @typescript-eslint/no-unused-varstest.svelte    3:12  error  'test' is defined but never used  @typescript-eslint/no-unused-vars    4:5   error  Unsafe return of an `any` typed value  @typescript-eslint/no-unsafe-return    5:12  error  Invalid operand for a '+' operation. Operands must each be a number or string. Got `any`  @typescript-eslint/restrict-plus-operands

What did you expect to happen?

I expected the same code to produce the same warnings, irrespective of appearing in a .svelte or .js file.

What actually happened?

It seems like the typescript-eslint parser cannot parse type information from the code in the .svelte files. Maybe the svelte-parser strips JSDoc comments from the code before forwarding it to the typescript parser?

Link toGitHub Repo with Minimal Reproducible Example

https://github.com/falco467/svelte-jsdoc-typescript-example

Additional comments

Migrated from eslint-plugin-svelte since it is a parser problem:sveltejs/eslint-plugin-svelte#767

Metadata

Metadata

Assignees

No one assigned

    Labels

    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