I have the following class:
@ObjectType()
class Input {
@Field()
id: string
@Field()
label: string
@Field()
element: Element
@Field()
defaultValue: '' // <-- HERE
}
This defaultValue can be either a string, an array (an array of strings, if it helps) or a boolean. So I tried to set it as defaultValue: string | string[] | boolean, tried to define a union type type DefaultValue = string | string[] | boolean (same thing, essentially), tried to change string[] to [string], but I kept getting this error message: Error: Undefined type error. Make sure you are providing an explicit type for the "defaultValue" of the "Input" class.
I tried to use createUnionType, but either I did it wrong, or it is incorrect way to do it in the first place
const DefaultValueUnion = createUnionType({
name: 'DefaultValueUnion',
types: [string, string[], boolean]
})
but I got an error, saying something like string is a type and it is used here as a value
Tried to use the CLI plugin, hoping it could determine the type automatically, but also no luck.
So is there any way to set a type as union? Or perhaps some workaround?