ARTICLE AD BOX
In the following code, why does the function notWorking pass Typescript compilation, but the function working fails with error TS2353: Object literal may only specify known properties, and 'x' does not exist in type 'AAA'.?
(Incidentally, notWorking DOES break compilation if I remove the property AAA.A...why?)
interface AAA { A: number; B?: number; } function notWorking(vals: number[]): AAA[] { // No typescript error! return vals.map(v => ({A: v, x: 'bad!'})); } function working(vals: number[]): AAA[] { // error TS2353 return vals.map((v): AAA => ({A: v, x: 'bad!'})); }