I am facing an issue while checking the length of union type array, string and number. Sample code of issue while build angular project in prod mode:
Variable in ts
public developerData: {
[key: string]: {
type: 'default';
data: string | number;
} | {
type: 'array',
data: Array < string | number | boolean >
}
} = {
'test': {
'type': 'array',
'data': ['1', '2', '3']
}
};
Html template
<div *ngIf="developerData['test']['type']=='array' && developerData['test']['data'].length >= 0">
Welcome
</div>
Prod build error
Property 'length' does not exist on type 'string | number | (string | number | boolean)[]'. Property 'length' does not exist on type 'number'.
Software versions
Angular: 7.3.5
TypeScript: 3.1.6
Node: 10.16.3
NPM: 6.9.0