Interfaces
interface User {
firstName: string;
lastName: string;
email: string;
age: number;
}const user: User = {
firstName: "harkirat",
lastName: "singh",
email: "[email protected]",
age: 21,
};Last updated
interface User {
firstName: string;
lastName: string;
email: string;
age: number;
}const user: User = {
firstName: "harkirat",
lastName: "singh",
email: "[email protected]",
age: 21,
};Last updated
function isLegal(user: User): boolean {
return user.age >= 18;
}import React from "react";
interface Todo {
id: number;
text: string;
completed: boolean;
}
interface TodoListProps {
todos: Todo[];
}
const TodoList: React.FC<TodoListProps> = ({ todos }) => {
return (
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.text}</li>
))}
</ul>
);
};
export default TodoList;interface Person {
name: string;
age: number;
greet(phrase: string): void;
}class Employee implements Person {
name: string;
age: number;
constructor(n: string, a: number) {
this.name = n;
this.age = a;
}
greet(phrase: string) {
console.log(`${phrase} ${this.name}`);
}
}