Warum Schnittstelle mit optionalen Eigenschaft wird anders als Schnittstelle ohne behandelt? Werden alle Eigenschaften für die Typassertion als optional betrachtet, wenn keine davon explizit optional definiert ist?Typoskript Typ Assertions - Schnittstelle mit optionalen Mitgliedern
interface WithOptionalProperty {
requiredProperty: string;
optionalProperty?: string;
}
//compilation error 'requiredProperty' is missing
let a = { optionalProperty: '' } as WithOptionalProperty;
interface WithoutOptionalProperties {
requiredProperty: string;
anotherRequiredProperty: string;
}
//but this works as expected
let b = { anotherRequiredProperty: '' } as WithoutOptionalProperties;
Ich bin immer noch verwirrt, was ist der Sinn der Zweirichtungsprüfung (A-> B | B-> A) –
'was ist das Punkt der bidirektionalen Kontrolle "Teilsicherheit, z Es ist Ihnen erlaubt, leicht von einer Elternklasse zu einer Kindklasse zu behaupten (weil es sehr wohl polymorph auf eine Kind-Instanz verweist). Sie dürfen jedoch keine sehr unsichere Aussage machen, ohne eine doppelte Aussage zu machen. – basarat