Let's say I am working on creating an array of type CoolObject
. What would be the better approach if some objects have the property format
, while others do not?
// Option 1
export interface CoolObject {
name: string;
color: string;
format? string;
}
or
// Option 2
export interface CoolObject {
name: string;
color: string;
format: string;
}
With the second option, I can easily check whether the format property has a value or not.