const x = [{a: 1, b: 2}].map((d: any) => ({...d, c: 'something new'}))
how can I make x has c property on array of object above?
I tried
const x = ([{a: 1, b: 2}] as any).map((d: <{c: string}>) => ({...d, c: 'something new'}))
but it doesn't seems it's the right syntax.
xwill be an array who's zero-th item will havea,b, andcproperties.(d: any) =>. Never annotate the parameter type of an inline call back. Ever.const x = [{a: 1, b: 2}].map(d => ({...d, c: 'something new'}). This uses type inference. You get more type information by writing fewer typesas anyyou're not getting much value out of the type system. For an unknown you should still have a good idea of it's shape or at least it's general constraints.