I have the following code:
type Period = "day" | "month" | "year";
let myPeriod: Period = "day";
const anyValue: any = {period: "wrong"};
myPeriod = anyValue.period;
console.log(myPeriod);
I want myPeriod
to have only the values day
, month
, or year
.
But the console prints out wrong
.
How can I modify my code to return a compile time error any time myPeriod
might not be one of day
, month
, or `year'?
(If I try something like let myPeriod: Period = "wrong"
, it does catch the error at compile time)