Search code examples
typescriptmongoosegraphqltypegraphqltypegoose

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?


Solution

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