Excess properties in TypeScript
· 2 min att läsa
Properties defined on an object that are not expressed by the type of the object are called excess properties.
Here's an example:
type Person = {
firstName: string
}
const person: Person = {
firstName: "Filip",
lastName: "Tammergård", // ⛔️ Object literal may only specify known properties, and 'lastName' does not exist in type 'Person'.
}
In this case, TypeScript makes it clear that lastName
is not defined in the Person
type and is therefore not allowed.