簡體   English   中英

Typescript 找不到模塊 `./app` 或其對應的類型聲明 ts(2307)

[英]Typescript cannot find module `./app` or its corresponding type declarations ts(2307)

Typescript 在src/main.ts的 VSCode 中顯示以下錯誤,但是當我運行項目時,它運行良好,沒有錯誤或警告。

在此處輸入圖像描述

我的 tsconfig 文件如下:

{
    "compilerOptions": {
        "outDir": "dist",
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "strict": true,
        "jsx": "preserve",
        "sourceMap": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "lib": ["esnext", "dom"],
        "baseUrl": "src",
        "allowJs": true,
        "paths": {
            "@/*": ["./*"],
            "~/*": ["./*"]
        },
        "suppressImplicitAnyIndexErrors": true
    },
    "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    "exclude": ["node_modules", "dist"]
}

App.vue位於src/App.vue文件內容如下

<template>
    <div>
        <!-- <h1 v-if="showModal">HELLO WORLDDNIOAS</h1> -->
        <!-- <SignInModal :show-modal="showModal" /> -->
        <HomePage />
        <!-- <router-view></router-view> -->
    </div>
</template>

<script lang="ts">
import { defineComponent, computed, ref } from "vue";
import HomePage from "@/components/HomePage.vue";
import SignInModal from "@/components/SignInModal.vue";
import Test from "@/components/Test.vue";
import { useStore } from "vuex";

export default defineComponent({
    name: "App",
    components: {
        HomePage,
        SignInModal,
        Test,
    },
    setup() {
        const store = useStore();
        const hello = ref(false);
        return {
            showModal: computed<boolean>(
                () => store.getters["modal/showModal"]
            ),
            hello,
        };
    },
});
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
}
</style>

我在shims-vue.d.ts中也有類型定義,如下所示:

import Vue, { DefineComponent } from "vue";
declare module "*.vue" {
    //eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
    const component: DefineComponent<{}, {}, any>;
    export { component, Vue };
}

如前所述,應用程序在控制台中加載正常且沒有錯誤,並且App.vue正確顯示。 為什么 VSCode 給我這個錯誤?

Vue 3 沒有導出Vue object,正確的模塊聲明如下:

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM