I want to define an object according to type. Within that object is an array consisting of elements that also correspond to a given type. However, I want to only push elements to this array later and initialize it empty for now. But it gives me an error and I can't figure this out. I have the following lines in my app.ts:
const publishObject: MqttPublishObject = {
IsTurnedOff: detail.isTurnedOff,
processType: detail.processType.name === "linear" ? 0 : 1,
anchorPoints: <MqttPublishAnchorPoint>[]
};
For which I get this errors:
src/app/app.ts(51,25): error TS2322: Type 'MqttPublishAnchorPoint' is not assignable to type 'any[]'.
src/app/app.ts(51,39): error TS2352: Conversion of type 'undefined[]' to type 'MqttPublishAnchorPoint' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
The typedefs are in the following files:
mqttPublishObject.ts:
export interface MqttPublishObject {
IsTurnedOff : boolean;
processType : number;
anchorPoints : MqttPublishAnchorPoint[];
}
mqttPublishAnchorPoint.ts
export interface MqttPublishAnchorPoint {
hour: number;
minute: number;
second: number;
intensity: number;
}
I feel I'm going about it the wrong way, but I don't see how. What exactly is the problem?
<MqttPublishAnchorPoint>[]means[] as MqttPublishAnchorPoint, not[] as MqttPublishAnchorPoint[]. This is probably the reason for error.