In my efforts to define explicit types in type-graphql for key-value pairs, I am encountering an issue. I have declared the key-value pair using [key: string]: string
, indicating that the keys can be of any string type and the values must be strings. This allows me to create objects like {a: 'a', b: 'b', c: 'c'}
where I can add key-value pairs freely. However, I am puzzled about how to specify an explicit type for this key-value pair in type graphql.
Below is a snippet of my code:
@ObjectType()
export class Result {
@Field({ nullable: true })
domainName?: string;
@Field(() => [String], { nullable: true })
uniqueIds?: string[];
@Field({ nullable: true })
resultKeyVal: { [key: string]: string };
}
The error I'm facing is: 'Unable to infer GraphQL type from TypeScript reflection system. You need to provide an explicit type for 'resultKeyVal' of the 'Result' class.'
If you look at the second field 'uniqueIds', I was able to provide an explicit type. However, when it comes to the third field 'resultKeyVal', I'm unsure about how to specify the explicit type.
Any guidance on achieving this would be greatly appreciated!