lodash - Conversión de tipos en Typescript al desestructurar
Supongamos esto
{foo, bar} = groupBy(arg);
Quiero convertir foo al tipo Foo y bar al tipo Bar. ¿Cómo puedo hacer esto?
Soy un completo principiante en Typescript. groupBy es el que viene del paquete lodash.
Respuesta #1
Si TypeScript no puede deducir el tipo del resultado de groupBy, podrías intentar afirmarlo tú mismo.
function groupBy(o: any) {
return o; // return any
}
let x = { a: 1, b: "1" }
// we know better than tsc and assert the type
let {a, b} = <{ a: number, b: string }>groupBy(x);
