In the following, I would expect this to fail as I've stated afternoon should be of type number, but it doesn't fail.
My guess is I'm destructuring incorrectly as hovering over the word afternoon when it returns shows the type as any (in VS Code).
Alternatively, it could all be wrong, this is literally my first play with Typescript, not getting it, yet!
const greetings = {
morning: "Good morning.",
evening: "Good evening.",
afternoon: "Good afternoon.",
};
interface AboutGreetingTypes {
morning: string,
evening: string,
afternoon: number,
};
const aboutGreeting = ({copy}): AboutGreetingTypes => {
const d = new Date();
const timeInHours = d.getHours();
const { morning, evening, afternoon } = copy;
if (timeInHours < 12) {
return morning;
}
if (timeInHours > 18) {
return evening;
}
if (timeInHours > 12) {
return afternoon;
}
};
console.log(aboutGreeting({copy: greetings}));
afternoon: "Good afternoon.",vs:afternoon: number,in the interface does not match. I don't get howcopygot into the mix.