type ValueOf<T> = T[keyof T];
interface IPerson {
name: string
age: number
hobby?: string[]
}
class Person implements IPerson {
name: string
age: number
hobby?: string[]
constructor(name: string, age: number, hobby: string[]) {
this.name = name
this.age = age
this.hobby = hobby
}
}
const output = new Person('john doe', 23, ['swimming', 'traveling', 'badminton'])
console.log(output)
//INTERFACE TYPE
interface Animal { type Animal = {
name: string; name: string;
} }
interface Bear extends Animal { type Bear = Animal & {
honey: boolean; honey: Boolean;
} }
const bear = getBear(); const bear = getBear();
bear.name; bear.name;
bear.honey; bear.honey;
interface LabeledValue {
label: string;
}
function printLabel(labeledObj: LabeledValue) {
console.log(labeledObj.label);
}
let myObj = { size: 10, label: "Size 10 Object" };
printLabel(myObj);Try
interface Person {
name: string;
age: number;
}
function greet(person: Person) {
return "Hello " + person.name;
}
Try
const modal = {} as IModal;
interface I1 {
x: any;
}
interface I2 {
y: {
a: I1,
b: I1,
c: I1
}
z: any
}
let myVar: I2['y']; // indexed access type
interface Person {
name: string;
age: number;
}
function greet(person: Person) {
return "Hello " + person.name;
}
Try