Issue
I don't know what would be the type of the function that returns an enum member. Here is my code so far:
interface Letter {
character: string,
color: Function
}
enum Color {
Green,
Yellow,
Grey
}
const letter_1: Letter = {
character: playerInput[0],
color: () => {
if (letter_1.character === playerInput[0])
return Color.Green;
else {
for (let i = 0; i < playerInput.length; i ++) {
if (letter_1.character === playerInput[i])
return Color.Yellow;
}
}
return Color.Grey;
}
};
In the Letter interface for now I set the type of color() to Function but I think there must be another type for it that I just don't know.
Solution
The type you're looking for is () => Color, i.e. a no-argument function that returns a Color enum value:
interface Letter {
character: string,
color: () => Color
}
enum Color {
Green,
Yellow,
Grey
}
const letter: Letter = {
character: '',
color: () => Color.Green
};
Answered By - Robby Cornelissen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.