4 ms·
why cant you have: type Message { contentA?: ContentAStructure, contentB?: ContentBStructure, } on read, you are already accessing the property data as
by hyuuu 4y ago
why cant you have:
type Message {
contentA?: ContentAStructure,
contentB?: ContentBStructure,
}
on read, you are already accessing the property data as typed right?
- matt_kantor 4y agoThat's not a union. Both `{}` and `{ contentA: a, contentB: b }` inhabit that type, so it doesn't represent "a value of type `Message` is either a value of `ContentAStructure` or a value of `ContentBStructure`".
- eatonphil 4y agoYou can but that's not type safe in TypeScript.