I find it is weird, so can someone confirm either these two are the same.
interface TypeA {
time: string | undefined;
}
interfaceTypeB {
time?: string;
}
They are similar, but not identical. Try the following for example:
interface TypeA {
time: string | undefined;
}
interface TypeB {
time?: string;
}
const exampleA: TypeA = {}
const exampleB: TypeB = {}
exampleA will give an error, because it needs the undefined time to be explicit. Merely omitting the property does not suffice. exampleB gives no error.
Playground link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With