-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Description
Bug Report
🔎 Search Terms
array map properties spread operator
🕗 Version & Regression Information
Always
Please keep and fill in the line that best applies:
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Array Mapping Allows Unknown Properties
⏯ Playground Link
💻 Code
interface Person {
firstName: string;
surname: string;
}
const father:Person = {
firstName: 'John',
surname: 'Smith'
};
const son:Person = {
...father,
// Correctly errors
FirstNaem: 'John Jr.'
};
const children:Person[] = ['John Jr', 'Susan'].map<Person>((ele, i) => ({
...father,
// Why doesn't this error?
FirstNaem: ele
}))
🙁 Actual behavior
Mapping an array of Person above lets you have typos in properties and define new properties
🙂 Expected behavior
The map function at the end should have the same error as when defining const son
Type '{ FirstNaem: string; firstName: string; surname: string; }' is not assignable to type 'Person'.
Object literal may only specify known properties, but 'FirstNaem' does not exist in type 'Person'. Did you mean to write 'firstName'?(2322)
Metadata
Metadata
Assignees
Labels
No labels