← Trail· Lesson 8 of 10
See this lesson in JavaScript →
Objects: a student and grades
Describe an object's shape with an interface and combine objects, arrays and functions.

An object groups named properties. In TypeScript, an interface describes its shape:
interface Aluno {
nome: string;
notas: number[];
}
With const aluno: Aluno, the editor knows aluno.nome is a string and aluno.notas a number[]. A missing property or a typo like aluno.nota is a type error. type Aluno = { ... } works similarly.
const prevents reassigning the variable, but aluno.nome = 'Bia' is allowed unless the interface marks it readonly. For the average, sum and divide by the count; an empty list returns null, and zero is a valid grade.
Try it
Change the name and grades. Removing notas would make the editor report a missing required property.
Execute o código para ver a saída aqui.Exercise
mediaDoAluno(aluno: Aluno): number | null returns the sum instead of the average. Divide by the count, keep null for an empty list and don’t modify the object. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o TypeScript e clique em Verificar.
Next step
Next: what the type checker catches, and what it doesn’t.