Below is the code snippet I am working with:
type Timeframe = "morning" | "afternoon" | "evening";
let myTimeframe: Timeframe = "morning";
const someValue: any = {time: "incorrect"};
myTimeframe = someValue.time;
console.log(myTimeframe);
I want myTimeframe
to only be assigned the values morning
, afternoon
, or evening
.
However, the console displays incorrect
.
Is there a way to modify my code so that it triggers a compile time error whenever myTimeframe
may not be one of morning
, afternoon
, or evening
?
(When I try something like
let myTimeframe: Timeframe = "incorrect"
, it does detect the error at compile time)