简体   繁体   English

Vue 3 + TypeScript TS2614:模块 '"*.vue"' 没有导出成员

[英]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; 
} 
  • Change Test.vue to Test.ts , and where import it as well.Test.vue更改为Test.ts ,并将其导入其中。
  • Change type 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.

相关问题 TS2614:模块没有导出成员“NextHandleFunction” - TS2614: Module has no exported member 'NextHandleFunction' 模块 '"*.vue"' 没有导出的成员 'Hoge'。 您的意思是改用“从“*.vue”导入会议吗?ts(2614) - Module '"*.vue"' has no exported member 'Hoge'. Did you mean to use 'import Meeting from "*.vue"' instead?ts(2614) Vue组件导入接口时如何避免TS2614错误 - How to avoid TS2614 error when importing interfaces from Vue components Vue / Typescript,得到模块 &#39;&quot;*.vue&quot;&#39; 没有导出成员 - Vue / Typescript, got Module '"*.vue"' has no exported member 模块 &#39;&quot;@react-native-firebase/firestore&quot;&#39; 没有导出成员 &#39;CollectionReference&#39;。 ts(2614) - Module '"@react-native-firebase/firestore"' has no exported member 'CollectionReference'. ts(2614) 模块没有导出的成员 Vue3 - Module has no exported Member Vue3 Vue 3:模块 '"../../node_modules/vue/dist/vue"' 没有导出成员 - Vue 3: Module '"../../node_modules/vue/dist/vue"' has no exported member 抑制使用Typescript时TS2305模块没有导出成员错误 - suppress TS2305 Module has no exported member error when using Typescript TypeScript 错误:TS2305:模块“./secretManager/secret”'没有导出成员 - TypeScript error : TS2305: Module '“./secretManager/secret”' has no exported member 打字稿错误TS2305:模块auth.service没有导出的成员&#39;AuthService&#39; - typescript error TS2305: Module auth.service has no exported member 'AuthService'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM