Skip to content

Commit

Permalink
Improve typing for Ramda #pick. (flow-typed#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSouthpaw authored and gantoine committed Oct 28, 2017
1 parent 1f42808 commit 007cfa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ declare module ramda {
declare function pathOr<T,V,A:NestedObject<V>>(or: T, p: Array<string>, ...rest: Array<void>): (o: ?A) => V|T;
declare function pathOr<T,V,A:NestedObject<V>>(or: T, p: Array<string>, o: ?A): V|T;

declare function pick<A>(keys: Array<string>, ...rest: Array<void>): (val: {[key:string]: A}) => {[key:string]: A};
declare function pick<A>(keys: Array<string>, val: {[key:string]: A}): {[key:string]: A};
declare function pick<O>(keys: $Keys<O>[], ...rest: Array<void>): (val: O) => O;
declare function pick<O>(keys: $Keys<O>[], val: O): O;

declare function pickAll<A>(keys: Array<string>, ...rest: Array<void>): (val: {[key:string]: A}) => {[key:string]: ?A};
declare function pickAll<A>(keys: Array<string>, val: {[key:string]: A}): {[key:string]: ?A};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ const path4:void = _.path([ 'a' ], null)

const pathOr: string|Object|number = _.pathOr('N/A', [ 'a', 'b' ], { a: { b: 2 } })

const pck: Object = _.pick([ 'a', 'd' ], { a: 1, b: 2, c: 3, d: 4 })
const pck1: Object = _.pick([ 'a', 'd' ], { a: 1, b: 2, c: 3, d: 4 })
//$ExpectError
const pck2: Object = _.pick([ 'a', 'b' ], { a: 1 })
// should allow passing in a typed object literal
const pickedObj: { a: string, b: number, c: boolean } = { a: 'hello', b: 1, c: true }
const pck3: { a: string, b: number } = _.pick(['a', 'b'], pickedObj)
//$ExpectError
const pck4: { a: string, b: string } = _.pick(['a', 'b'], pickedObj)

const ooo = { a: 1, b: 2, A: 3, B: 4 }
const isUpperCase = (val, key) => key.toUpperCase() === key
Expand Down

0 comments on commit 007cfa3

Please sign in to comment.