Mahdi Ta'ala
Mahdi Ta'ala

Reputation: 380

Pass typescript type Problem in type-graphql

I am new with GraphQL and I don't know how to pass a TypeScript type to ReturnTypeFunction of @Field decorator.

my code is as below :

export type WorokingHours = [number, number];

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

and I will get this error message:

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

how can fix this error?

do you have any idea to implement the duration that my stores are actives in my DB?

Upvotes: 3

Views: 341

Answers (2)

Michał Lytek
Michał Lytek

Reputation: 12077

GraphQL spec doesn't support tuples, so you need to use list [Number] or explicit object type { one: number, two: number } instead.

Upvotes: 1

hasezoey
hasezoey

Reputation: 1096

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]]

Upvotes: 0

Related Questions