Skip to content

Reactive variable doesn't do type inference #206

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
4 tasks done
baseballyama opened this issue Aug 30, 2022 · 2 comments · Fixed by #207
Closed
4 tasks done

Reactive variable doesn't do type inference #206

baseballyama opened this issue Aug 30, 2022 · 2 comments · Fixed by #207
Labels
bug Something isn't working

Comments

@baseballyama
Copy link
Member

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?

8.23.0

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

What did you do?

Configuration
module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  globals: {
    window: true,
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 2021,
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.eslint.json'],
    extraFileExtensions: ['.svelte'],
  },
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'plugin:svelte/recommended',
  ],
  rules: {},
  overrides: [
    // see: https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/TROUBLESHOOTING.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
    {
      files: ['*.ts'],
      rules: {
        'no-undef': 'off',
      },
    },
    {
      files: ['**/*.svelte'],
      parser: 'svelte-eslint-parser',
      parserOptions: {
        parser: '@typescript-eslint/parser',
      },
      rules: {
        'no-undef': 'off',
      },
    },
  ],
};

<script lang="ts">
  let obj = {
    child: {
      title: "hello!",
    },
  };

  $: child = obj.child;
  $: title = child?.title ?? "Yo!";
</script>

{child}{title}

What did you expect to happen?

No ESLint error comes.

What actually happened?

/Users/baseballyama/Desktop/git/issue-eslint-plugin-svelte-1/src/Sample.svelte
  9:6   error  Unsafe assignment of an `any` value            @typescript-eslint/no-unsafe-assignment
  9:14  error  Unsafe member access .title on an `any` value  @typescript-eslint/no-unsafe-member-access

✖ 2 problems (2 errors, 0 warnings)

image

Link to Minimal Reproducible Example

https://github.com/baseballyama/issue-eslint-plugin-svelte-1

Additional comments

I think this is because TypeScript AST is inferred to any.
I'll try to fix this, but before that I would confirm how to fix it.
Do we need to type infer by inserting a dummy let child = obj.child; or something else?

@ota-meshi
Copy link
Member

Thank you for posting this issue!

Do we need to type infer by inserting a dummy let child = obj.child; or something else?

I have opened a PR to modify to insert dummy code. #207

@baseballyama
Copy link
Member Author

Wao! Thank you! Super fast!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants