Interface Typescript
Mahabubur Rahman
Posted on May 3, 2023
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];
💖 💪 🙅 🚩
Mahabubur Rahman
Posted on May 3, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.