Message from JavaScript discussions

November 2020

— Thank you for your advices guys!

— 

const pick = <O, Keys extends (keyof O)[]>(obj: O, keys: Keys) =>
Object.fromEntries(
(Object.entries(obj) as [keyof O, O[keyof O]][]).filter(([k, v]) =>
keys.includes(k)
)
) as { [K in keyof O]?: O[K] } & { [K in Keys[number]]: O[K] };

— My attempt at an implementation Flavius

— Kinda messy, but seems to work correctly

— Well this one is working

— Why as any

— This.track doesn¡t return anything... so

— And I didn't use it

— const pick = <O>(obj: O, keys: (keyof O)[]) =>
Object.fromEntries(
(Object.entries(obj) as [keyof O, O[keyof O]][]).filter(([k, v]) =>
keys.includes(k)
)
) as { [K in keyof O]: O[K] };

Message permanent page

— This is stricter

— const pick = <O, Keys extends (keyof O)[]>(obj: O, keys: Keys) =>
Object.fromEntries(
(Object.entries(obj) as [keyof O, O[keyof O]][]).filter(([k, v]) =>
keys.includes(k)
)
) as { [K in Keys[number]]: O[K] };

Message permanent page

— Fixed*