I have an interface like:
interface Props {
readonly date: Date | null;
}
How is it possible that my console output shows undefined when the type only allows for a Date or null value?
const MyTimestamp = ({date}: Props) => {
console.log("date=" + date); // outputs undefined
}
Because Typescript != Javascript.
Your Javascript console.log logs the value date at run time. Javascript doesnt know types, like Typescript, so date can be anything.
Typescript is only for you. To help you write "cleaner" code.