I have custom types which is the following:
hero?: string
power?: string
I want to add those type into an array, which is part of another type
type Superheroes = {
character: string[] | []
villains: number | null
city: string
}
When I try to use the type (see below) I get the following error Typescript: Type 'string | undefined' is not assignable to type 'string'
return {
character: [hero, power],
villains: 2 || null,
city: 'new york' || null
}
What is the correct way to define hero and power types inside the character array?