typescript object with any properties 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 {
console.log(args.property1);
}
Example 2: typescript string in object property
protected get ButtonClass(): object {
const buttonClass = {
'cursor-pointer hover:shadow focus:shadow': this.Enabled,
'opacity-40 cursor-not-allowed': !this.Enabled,
'whitespace-no-wrap': !this.LineBreaks
}
buttonClass[`hover:${this.Color.FocusColorClass}`] = this.Enabled;
buttonClass[`focus:${this.Color.FocusColorClass}`] = this.Enabled;
buttonClass[`active:${this.Color.ActiveColorClass}`] = this.Enabled;
return buttonClass;
}
Example 3: typescript operate with html objects
ts
const app = document.getElementById("app");
const p = document.createElement("p");
p.textContent = "Hello, World!";
app?.appendChild(p);