Is there a difference in how interfaces with optional properties are treated compared to those without them? If none of the properties in an interface are defined as optional, are they all considered optional for type assertion?
interface WithOptionalProperty {
requiredProperty: string;
optionalProperty?: string;
}
//When 'requiredProperty' is missing, compilation error occurs
let a = { optionalProperty: '' } as WithOptionalProperty;
interface WithoutOptionalProperties {
requiredProperty: string;
anotherRequiredProperty: string;
}
//This works as expected even if no properties are defined as optional
let b = { anotherRequiredProperty: '' } as WithoutOptionalProperties;