I have the following code
export interface A {
redApple: props[];
yellowApple: props[];
redYellowApple: props[];
}
export type FruitColour = "red" | "yellow | "green";
export type Fruit = "apple" | "banana | "cherry";
const x = [
"redApple",
"yellowApple",
"redYellowApple",
"greenCherry"
]
export const changeFruit = (
fruit: Fruit,
colour: Colour
): keyof A => {
return x
.filter((string) => string.match(colour + fruit))
.splice(0, 1)
.toString();
};
I keep getting Type 'string' is not assignable to type 'keyof IndexViewDataItem'. I can use myFunction(someField: keyof A | string) but then I lose type guarding.
Any help or guidance would be greatly appreciated.
Fruit? What isColour?fruit + colour. Also,arrayis an odd name for a parameter that will be a string, not an array. And thematchmethod probably isn't what you're looking for there.keyof Ais"colour" | "otherProperties". Your function returnsstring, which you can't assign to the type"colour" | "otherProperties". Also, none of the values in the array match either property name.