TypeScript
Wat zijn interfaces in TypeScript?
Shape objects met interfaces.
Interfaces
Define object shape CanContract parameters Optional properties Readonly properties
Code Voorbeelden
TYPESCRIPTInterfaces
interface User {
id: number;
name: string;
email?: string; // Optional
readonly createdAt: Date; // Readonly
}
function printUser(user: User) {
console.log(user.name);
}
const user: User = {
id: 1,
name: "Jan",
createdAt: new Date()
};Relevante trefwoorden
interfaceshapecontract