I am trying to create an object with specific type properties. Inside this object, there is an array that should only contain elements of a certain type. I want to initialize the array as empty and push elements into it later on. However, I am encountering an error that I cannot seem to resolve. The code snippet from my app.ts is as follows:
const publishObject: MqttPublishObject = {
IsTurnedOff: detail.isTurnedOff,
processType: detail.processType.name === "linear" ? 0 : 1,
anchorPoints: <MqttPublishAnchorPoint>[]
};
But I am getting the following 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 type definitions are located in the respective 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 believe my approach might be incorrect, but I am struggling to identify the issue. Can someone point out what exactly is causing the problem?