pick.ts
1 /** 2 * Let's say you have the following JSON 3 * ```json 4 * [ { name: "hello" }, { name: "world" } ] 5 * ``` 6 * and you want to make an array with only the `name` property. 7 * 8 * You can use this `pick` function which takes a string for the 9 * property to pick. 10 * 11 * @example 12 * class Model { 13 * \@deserializeWith(u.pick("name")) 14 * names = t.array(t.string()); 15 * } 16 * 17 * const model = deserialize(Model, { 18 * names: [ { name: "hello" }, { name: "world" } ] 19 * }); 20 * 21 * console.log(model.names); // ["hello", "world"] 22 */ 23 export const pick = (item: string) => (arr: Array<any>) => arr.map((local) => local[item]);