interface IMessage {
value: string;
length?: string;
}
function saySize(message: IMessage|IMessage[]) {
if (message instanceof Array) {
return message.length;
}
}
This snippet compiles, but lengthis required lengthfor IMessage. If not specified, the error is:
unions.ts(8,24): error TS2339: Property 'length' does not exist on type 'IMessage | IMessage[]'.
I find this counterpoint because I need to make an assumption that it IMessagecan be used as an array type. Is adding the required length really, or am I making a mistake?
source
share