alkis alkis - 1 year ago 96
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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download