Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 475
Mahdi Ta'ala Avatar asked Jun 09 '26 21:06

Mahdi Ta'ala


1 Answers

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

like image 95
Michał Lytek Avatar answered Jun 11 '26 11:06

Michał Lytek