[英]Vue 3 + TypeScript TS2614: Module '"*.vue"' has no exported member
I'm trying to make named export in one component like this:我正在尝试在一个组件中进行命名导出,如下所示:
export interface ITest { t: String }
to call it from another:从另一个人那里调用它:
import { ITest } from '@/components/Test.vue'
And have the error:并有错误:
TS2614: Module '"*.vue"' has no exported member 'ITest '. Did you mean to use 'import ITest from "*.vue"' instead?
And if I change to: import ITest from '@/components/Test.vue'
如果我更改为:
import ITest from '@/components/Test.vue'
The error now says: Module '"(path)/Test.vue"' has no default export. Did you mean to use 'import { ITest } from "(path)/Test.vue"' instead?
错误现在说:
Module '"(path)/Test.vue"' has no default export. Did you mean to use 'import { ITest } from "(path)/Test.vue"' instead?
Module '"(path)/Test.vue"' has no default export. Did you mean to use 'import { ITest } from "(path)/Test.vue"' instead?
How to make named export in Vue using TypeScript?如何使用 TypeScript 在 Vue 中进行命名导出?
Vue 3, TypeScript, Webpack 5. Vue 3、TypeScript、Webpack 5。
export interface ITest {
t: string;
}
Test.vue
to Test.ts
, and where import it as well.Test.vue
更改为Test.ts
,并将其导入其中。String
to typescript type string
String
更改为打字稿类型string
Don't export at setup section.不要在设置部分导出。
The following works:以下作品:
<script lang="ts">
export interface ITest { t: string }
</script>
I have also wondered this, and didn't find any workarouds, until finally I found this by myself.我也想知道这个,并没有找到任何解决方法,直到最后我自己找到了这个。
You can take a look at your shims-vue.d.ts
and you can find it's probably analizing setup block to infer the definition of a component behind the scene.您可以查看您的
shims-vue.d.ts
,您会发现它可能正在分析设置块以推断场景背后组件的定义。
That is to say, the setup block defines the type DefineComponent<{}, {}, any>
, so there may be no spaces for exporting any static type.也就是说 setup 块定义了类型
DefineComponent<{}, {}, any>
,所以导出任何静态类型都可能没有空格。 Thus I tried to export it in pure script block, and it worked.因此,我尝试将其导出为纯脚本块,并且成功了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.