简体   繁体   中英

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

Typescript is showing the following error within VSCode in src/main.ts , however when I run the project it runs fine without errors or warnings.

在此处输入图像描述

My tsconfig file is as follows:

{
    "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 is found in src/App.vue the file contents are below

<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>

I've also got type definitions in shims-vue.d.ts as follows:

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 };
}

As mentioned the app loads fine without errors in the console and App.vue displays correctly. Why is VSCode giving me this error?

Vue 3 doesn't have exported Vue object and the correct module declaration is the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM