Subscribe on changes!

[求助]vue文件引用ts时没有类型推断, 并且一直提示错误

avatar
Dec 28th 2022

Vue version

3.2.31

Link to minimal reproduction

Steps to reproduce

我的eslint配置是

module.exports = {
  root: true,
  env: {
    browser: true,
    commonjs: true,
    es2021: true,
    node: true,
    'vue/setup-compiler-macros': true,
  },
  plugins: ['vue'],
  parser: 'vue-eslint-parser',
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 'latest',
    parser: '@typescript-eslint/parser',
  },
  extends: [
    'plugin:vue/vue3-recommended',
    'eslint:recommended',
    'standard-with-typescript',
  ],
  ignorePatterns: ['.eslintrc.cjs', 'tsconfig.app.json'],
  rules: {
    'vue/require-default-prop': 'off',
    'vue/multi-word-component-names': 'off',
    'vue/attribute-hyphenation': 'off',
    'vue/no-v-html': 'off',
    indent: [
      'warn',
      2,
      {
        SwitchCase: 1,
        ignoredNodes: ['ConditionalExpression'],
      },
    ],
    'linebreak-style': ['warn', 'unix'],
    quotes: ['warn', 'single'],
    semi: ['warn', 'always'],
    camelcase: ['warn', 'always', { ignoreDestructuring: true }],
    'linebreak-style': 0,
    'comma-dangle': 'off',
  },
  globals: {
    process: true,
    yw: true,
    tinymce: true,
    BeaconAction: true,
    echarts: true,
  },
};

我的代码如下, 运行是正常的, 但是没有对应的类型推断, ts提示 未从源文件“/Users/zhaozhongyu/code/write-pc/src/renderer/utils/fetch.ts”生成输出文件“/Users/zhaozhongyu/code/write-pc/src/renderer/utils/fetch.d.ts”。

<script setup lang="ts">
import { _fetch } from '@utils/fetch';
</script>

What is expected?

按理说应该直接有对应的类型推断, 不需要我手写一个d.ts类型文件

What is actually happening?

除非手写一个d.ts类型文件, 否则不会有类型推断.

System Info

No response

Any additional comments?

No response

avatar
Dec 28th 2022

Please provide a minimal reproduction to reopen the issue. Thanks.

https://antfu.me/posts/why-reproductions-are-required

avatar
Dec 28th 2022

确定了, 只要在tsconfig.json中包含了includes就会有问题

"include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.vue"
  ],