【发布时间】:2021-04-20 14:31:45
【问题描述】:
我在我的 Vue 组件脚本部分中定义了一个接口,当我尝试将它导入另一个打字稿文件时出现此错误:
TS2614: Module '"../pages/categories/alimentation/index.vue"' has no exported member 'BenefitDetails'. Did you mean to use 'import BenefitDetails from "../pages/categories/alimentation/index.vue"' instead
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
export interface BenefitDetails {
name: string
frequency: string
cost: number
icon: string
description: string
}
@Component
export default class MyComponent extends Vue {
// my props ...
mounted() {}
}
</script>
// Error in import below
import { BenefitDetails } from '~/pages/categories/alimentation/index.vue'
export function getBenefitFrequencyColor({ frequency }: BenefitDetails) {
switch (frequency) {
case 'Mensal':
return 'blue'
default:
return 'yellow'
}
}
我在this 问题中找到了 VSCode 的解决方案,但我正在使用 webstorm
更新:我不想将接口声明移动到另一个文件
【问题讨论】:
-
请发布您的代码文本而不是屏幕截图
-
在
tsconfig.json中,compilerOptions.allowSyntheticDefaultImports是否设置为true?如果没有,请添加它,这应该可以解决问题。 -
仅将此设置添加到
tsconfig.json不起作用。使用此设置重新启动 IDE 是可行的,但我也注意到,无论对tsconfig.json进行任何更改,只要重新启动 IDE 问题就消失了 -
重启 webstorm 为我解决了这个问题。
标签: typescript vue.js webstorm