typescript typing objects code example
Example 1: define object properties typescript
interface ISomeObject {
subPropertie1: string,
subPropertie2: number,
}
interface IProperties {
property1: string,
property2: boolean,
property3: number[],
property4: ISomeObject,
property5: ISomeObject[],
}
function (args:IProperties): void { // Sample Usage
console.log(args.property1);
}
Example 2: typing in typescript
var name: string = "Anna";
let notes: (number | string)[] = ["Get Food", 23, "Call the previous number when betting"];
Example 3: typescript obejct replace propertyies
const recievedKeys = Object.keys(receivedObject) as Array<keyof IEvent>
for (const key of recievedKeys) {
this.event = {
...this.event,
[key]: receivedObject[key]
}
}