Objects and Interfaces
Interfaces
Interfaces name an object shape so values and functions can share the same contract.
Interfaces
interface.ts
interface Student {
name: string;
score: number;
}
function describe(student: Student): string {
return `${student.name}: ${student.score}`;
}
const score: number = ;
const student: Student = {
name: "Ada",
score: score
};
const summary: string = describe(student);
console.log(summary);
interface Student {
name: string;
score: number;
}
function describe(student: Student): string {
return `${student.name}: ${student.score}`;
}
const score: number = ;
const student: Student = {
name: "Ada",
score: score
};
const summary: string = describe(student);
console.log(summary);
interface Student {
name: string;
score: number;
}
function describe(student: Student): string {
return `${student.name}: ${student.score}`;
}
const score: number = ;
const student: Student = {
name: "Ada",
score: score
};
const summary: string = describe(student);
console.log(summary);
interface
An interface describes property names and value types for an object.