[英]How to avoid TS2614 error when importing interfaces from Vue components
I have defined an interface in my Vue component script section and when I tried to import it in another typescript file this error appear:我在我的 Vue 组件脚本部分定义了一个接口,当我尝试将它导入另一个 typescript 文件时,出现此错误:
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'
}
}
I found a solution to VSCode in this question but I'am using webstorm我在这个问题中找到了 VSCode 的解决方案,但我正在使用 webstorm
UPDATE: I do not want to move the interface declaration to another file更新:我不想将接口声明移动到另一个文件
Try declaring BenefitDetails interface in de dedicated ts file (ie: benefitDetails.model.ts)尝试在专用 ts 文件中声明 BenefitDetails 接口(即:benefitDetails.model.ts)
Then import the BenefitDetails where needed然后在需要的地方导入 BenefitDetails
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.