1

我是 GraphQL 的新手,我不知道如何将 TypeScript 传递typeReturnTypeFunction装饰@Field器。

我的代码如下:

export type WorokingHours = [number, number];

// [ [ 8, 13 ], [ 16, 22 ] ]
@Field(() => [WorokingHours], {
   nullable: true,
   description: storeWorkingHours
})
@prop()
workingHours?: WorokingHours[];

我会收到这个错误信息:

'WorokingHours' only refers to a type, but is being used as a value here.ts(2693)

如何解决此错误?

你有什么想法来实现我的商店在我的数据库中活跃的持续时间吗?

4

2 回答 2

1

GraphQL 规范不支持元组,因此您需要使用列表[Number]或显式对象类型{ one: number, two: number }

于 2020-07-14T09:18:50.630 回答
0

its simple, you have defined an type, which only exists at compilation time of typescript, not on runtime

for typegoose you need to manually set an array type anyways, for you case (on 7.2.0) it would be prop options { type: Number, dim: 2 }

and for GraphQL i guess it would be () => [[Number]]

于 2020-06-18T11:14:23.557 回答