How come I am able to map properties that do not exist on type T when using Array.map<T>
?
I have set strict: true
in my tsconfig.json
interface MappedItem {
foo: number;
}
const arr = [1, 2, 3];
// I would anticipate an error here, but it does not occur
arr.map<MappedItem>(n => ({ foo: n, bar: n }));
arr.map(n => {
// Here is where the expected error occurs
// Object literal may only specify known properties, and 'bar' does not exist in type 'MappedItem'
const item: MappedItem = { foo: n, bar: n };
return item;
});