How to use Index signatures as types #1303
Answered
by
MichalLytek
lantos1618
asked this question in
Q&A
-
Hi, I've been looking on stacker overflow, the typegraphql and on the gitter chat on how implement types with index signatures. How can you use index signatures as types? import { ObjectType } from "type-graphql";
import { GraphQLJSONObject } from "graphql-type-json";
@ObjectType()
export class Label {
@Field(of => GraphQLJSONObject, { nullable: true })
[label: string]: string
}
|
Beta Was this translation helpful? Give feedback.
Answered by
MichalLytek
Jul 3, 2022
Replies: 1 comment
-
You need to represent the object with dynamic keys as an array of key-value objects. @ObjectType()
export class LabelValue {
@Field()
label: string;
@Field()
value: string;
}
@ObjectType()
export class Foo {
@Field(() => [LabelValue])
labels: LabelValue[];
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lantos1618
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to represent the object with dynamic keys as an array of key-value objects.