unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.29k stars 198 forks source link

<script setup lang="ts"> cannot find name 'onMounted' #138

Closed mariusa closed 2 years ago

mariusa commented 2 years ago

onMounted works fine for <script setup> with vscode, no warnings. .eslintrc has

extends: ["eslint:recommended", "plugin:vue/base", "plugin:vue/vue3-essential", "plugin:vue/vue3-recommended", "plugin:vue/vue3-strongly-recommended", "@antfu"],

Adding lang="ts" makes vscode show warning cannot find name 'onMounted', but $ref has no warning.

How to solve this?

Maybe related to https://github.com/antfu/unplugin-auto-import/issues/61 ?

antfu commented 2 years ago

We temporarily close this due to the lack of enough information. Please provide a minimal reproduction to reopen the issue. Thanks.

mariusa commented 2 years ago

Looking at vitesse (thanks for it), found the solution: Add to AutoImport in vite config:

dts: 'src/auto-imports.d.ts',
beierzhijin commented 2 years ago

for me, it has fixed the problem: add *.d.ts to tsconfig.json

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