Using Object
interface IUser {
name: string;
age: number;
}
const userWithInterface: IUser = {
name: "interface",
age: 200,
};
Extend Interface
interface IExtendUser extends IUser {
role: string;
}
const user1: IExtendUser = {
age: 200,
name: "Extend Interface",
role: "Admin",
};
Using Function
interface IAddNumbers {
(num1: number, num2: number): number;
}
const addNumbers: IAddNumbers = (num1, num2) => num1 + num2;
Using Array
interface IRollNumbers {
[index: number]: number;
}
const rollNumbers: IRollNumbers = [1, 4, 5];
Top comments (0)