【问题标题】:typeof 'enum' is not assignable to parameter of type 'ClassType<unknown>'typeof 'enum' 不可分配给 'ClassType<unknown>' 类型的参数
【发布时间】:2020-04-07 09:29:06
【问题描述】:

我想创建抽象的通用订单类,如下所示

export function Order<T>(OrderItem: ClassType<T>) {
    @InputType({ isAbstract: true})
    abstract class Order implements IOrder<OrderItem>{
        @Field(type => OrderItem)
        field: OrderItem;

        @Field(type => OrderByDirection)
        direction: OrderByDirection;
    }

}

我从枚举创建一个订单项

export enum BaseOrderItem {
    CREATED_AT = "createdAt",
}

当我将枚举放入 T 时,我得到了 TS2345,

BaseOrderItem 的类型不能分配给“ClassType”类型的参数

@InputType()
export class TestOrder extends Order(BaseOrderItem) {}

如何使用枚举动态输入类型??

当我解除“ClassType”限制时

export function Order<T>(OrderItem) {
    @InputType({ isAbstract: true })
    abstract class Order implements IOrder<T> {
        @Field(type => OrderItem)
        field: T;

        @Field(type => OrderByDirection, { nullable : true})
        direction: OrderByDirection;
    }
}

我收到消息

type 'void' is not a constructor function type 

【问题讨论】:

    标签: graphql typegraphql


    【解决方案1】:

    如果您想使用枚举,只需解除 ClassType 限制即可。

    IOrder&lt;OrderItem&gt; 可能也是如此。

    【讨论】:

    • 抱歉回复晚了。当我解除 ClassType 限制时,我收到如下消息。类型'void'不是构造函数类型
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2021-11-11
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2022-06-16
    相关资源
    最近更新 更多