typescript object type code example
Example 1: typescript type object
type Dictionary = {
[key: string]: any
}
Example 2: 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 3: typescript object type
let endedCoord: {x: number, y: number} = {
x: -1,
y: -1,
}
Example 4: typescript class type t
class GenericNumber<T> {
zeroValue: T;
add: (x: T, y: T) => T;
}
let myGenericNumber = new GenericNumber<number>();
myGenericNumber.zeroValue = 0;
myGenericNumber.add = function(x, y) { return x + y; };
Example 5: angular type of string
if(typeof myVariable === 'string'){
}
Example 6: typescript operate with html objects
ts
const app = document.getElementById("app");
const p = document.createElement("p");
p.textContent = "Hello, World!";
app?.appendChild(p);