模块没有导出成员 Vue Ts

时间:2021-04-15 08:41:25

标签: typescript vue.js vuejs3

我试图在我的组件中导入我自己的类型,但发生了一些奇怪的事情。所以如果我这样做:

类型

export type Size = 'foo' |'foo' | 'foo' | 'foo';
export type Type = 'foo' | 'foo' | 'foo' | 'foo';
export type State = 'foo'

组件

    import { Size, State, Type } from '@/typings/button-type';
    
    props: {
            size: {
                default: 'foo',
                type: String as PropType<Size>
            },
            state: {
                default: 'foo',
                type: String as PropType<State>
            },
            type: {
                default: 'foo',
                type: String as PropType<Type>
            }
        },

这很好用。 但是现在我想添加颜色类型,或者只是将所有类型放在我想要创建和使用它们的按钮类型中;我收到一个错误。我不知道为什么它适用于这 3 种类型而不适用于其他类型。

类型失败

    export type MyOwnType = {
        color: Color;
        size: Size;
        type: Type;
        state: State;
    }

type Color = 'foo' | 'foo';
type Size = 'foo' |'foo' | 'foo' | 'foo';
type Type = 'foo' | 'foo' | 'foo' | 'foo';
type State = 'foo'

export type Color = 'foo' | 'foo';
export type Size = 'foo' |'foo' | 'foo' | 'foo';
export type Type = 'foo' | 'foo' | 'foo' | 'foo';
export type State = 'foo'

我尝试做的:

            color: {
                default: 'foo',
                type: String as PropType<Color>
            }

或与 PropType 之类的对象相同,我得到相同的错误

错误


src/components/Btn/Btn.vue:11:14
TS2305: Module '"../../typings/button-type"' has no exported member 'Color'.
     9 |     import { defineComponent, computed, PropType } from '@vue/runtime-core';
    10 |     import { useI18n } from 'vue-i18n';
  > 11 |     import { Color, Size, State, Type } from '@/typings/button-type';
       |              ^^^^^

Color、MyOwnType 或 Foo... 都没有导出成员。

有什么想法吗?

0 个答案:

没有答案