objects in typescript code example
Example 1: typescript type object
type Dictionary = {
[key: string]: any
}
Example 2: array of objects typescript
let userTestStatus: { id: number, name: string }[] = [
{ "id": 0, "name": "Available" },
{ "id": 1, "name": "Ready" },
{ "id": 2, "name": "Started" }
];
userTestStatus[34978].nammme;
Example 3: 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 {
console.log(args.property1);
}
Example 4: typescript operate with html objects
ts
const app = document.getElementById("app");
const p = document.createElement("p");
p.textContent = "Hello, World!";
app?.appendChild(p);