Skip to content

Type inferred as any in .svelte file. #713

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

Closed
2 tasks done
Stadly opened this issue Mar 19, 2024 · 1 comment
Closed
2 tasks done

Type inferred as any in .svelte file. #713

Stadly opened this issue Mar 19, 2024 · 1 comment

Comments

@Stadly
Copy link

Stadly commented Mar 19, 2024

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.57.0

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

2.35.1

What did you do?

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

<script lang="ts">
  export let transition:
    | {
        duration?: number;
      }
    | undefined = undefined;
  if (transition) {
    // transition.duration should not be inferred as any but number
    transition.duration = transition.duration ?? 1500;
  }
</script>

What did you expect to happen?

transition.duration should be inferred as number.

If you look at transition.ts in the reproduction, you'll see it works correctly for .ts files, so it seems to be an issue with .svelte files.

What actually happened?

transition.duration is inferred as any.

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/Stadly/reproduction/tree/eslint-plugin-svelte/type-inferred-as-any

Additional comments

No response

@ota-meshi
Copy link
Member

Duplicate of #298

@ota-meshi ota-meshi marked this as a duplicate of #298 Mar 21, 2024
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

2 participants