vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.45k stars 666 forks source link

Typescript: Eslint can't detect types exported from Vue SFC #2375

Open jordan-erisman opened 8 months ago

jordan-erisman commented 8 months ago

Checklist

Tell us about your environment

Please show your full configuration:

module.exports = {
  ignorePatterns: ['tsconfig.json', '*.config.js', '*.config.ts'],
  extends: [
    'eslint:recommended',
    'plugin:vue/vue3-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
  ],
  plugins: ['@typescript-eslint'],
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: '@typescript-eslint/parser',
    project: ['tsconfig.json'],
    extraFileExtensions: ['.vue'],
  },
};

What did you do?

Reproduction link (StackBlitz). Run npm run lint

Child

<script lang="ts">
export type MyType = {
  test: string;
};
</script>

....

Parent

<script setup lang="ts">
import {type MyType} from './Child.vue';

// Unsafe assignment of an `any` value
const obj: MyType = { test: '123' };

// Unsafe member access .test on an `any` value
const test = obj.test;
</script>

What did you expect to happen? The imported types to work. Typescript recognizes the type and does not complain, but eslint throws and error.

What actually happened?

  14:7   error  Unsafe assignment of an `any` value           @typescript-eslint/no-unsafe-assignment
  14:16  error  Unsafe member access .test on an `any` value  @typescript-eslint/no-unsafe-member-access

✖ 2 problems (2 errors, 0 warnings)

Repository to reproduce this issue

Reproduction link (StackBlitz). Run npm run lint

mcmule commented 3 weeks ago

Hi! Are there any news regarding this? We've a new project with Vue3 and latest TS. Despite all our efforts (and experience with these tools, including older eslint), eslint returns the same errors, basically any "unsafe-" rule will raise errors on imported SFCs usage. Is it a missing feature, as flagged 8 months ago? A misconfiguration? or a bug?

@jordan-erisman , did you solve this?

AlanLes commented 1 day ago

Recently, I've encountered the same problem. Have you been able to solve this issue somehow, guys? :)