alkis alkis - 8 months ago 73
TypeScript Question

Typescript type casting when destructuring

Let's assume this

{foo, bar} = groupBy(arg);

I want to cast foo to type
and bar to type
. How can I do this?

I'm a complete beginner with Typescript.
is the one from lodash package.

Answer Source

You can define the type of each variable in the deconstruction definition.

let x = { a: 1, b: "1" }

let {a: number, b: string} = x;