Issue
I have that object that I want to use as a type:
interface MyInput {
id: string,
label: string,
setter: Function,
type: string,
value: string | string[] | boolean,
options?: string[]
}
I have some errors like: Property 'map' does not exist on type 'string | boolean | string[]'. Type 'string | boolean | string[]' is not assignable to type 'boolean | undefined'.
The thing is that I will always know whether my value is string[], boolean or string with my type property.
Is there any solution to remove those errors without make 3 different interfaces?
Beside putting my value property to any or to create 3 diffent types, I do not known.
Solution
You will need to do something to cast it or annotate it with a @ts-ignore
. e.g.
(input.value as string[]).map(...
Answered By - possum
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.