Skip to content

#440 introduces TypeScript regression #746

@abrahamguo

Description

@abrahamguo

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

  • I'm using eslint-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 in eslint-plugin-svelte repo and open the issue in eslint-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?

None (using parser only)

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

  • svelte-eslint-parser@1.3.1

What did you do?

No configuration.

Code snippet A:

<script lang='ts'></script><input onchange={e => {e; let b;}} />

Code snippet B:

<script lang='ts'></script><input onchange={e => {e; let b: number;}} />

What did you expect to happen?

The _virtualScriptCode returned by svelte-eslint-parser for both A and B should include a type annotation on e.

What actually happened?

The _virtualScriptCode returned by svelte-eslint-parser only includes a type annotation on e for code snippet A.

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/abrahamguo/repro/tree/svelte-typed

Additional comments

In #440, @baseballyama added hasTypeInfo, which recurses downwards through the AST looking for any TypeScript node. If it finds any child TypeScript node, then it skips adding a type.

However, this logic is far too broad. As we can see in this example, adding any TypeScript node anywhere in the descendant AST — even if it's completely unrelated — causes the type annotation on e to be skipped, which then causes downstream problems with typescript-eslint picking it up as any.

I believe that this may be the root cause of some of the other currently open issues in this repo regarding TypeScript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions