-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pluck): pluck now can return object (#71)
- Loading branch information
Showing
2 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { Placeholder } from 'ramda'; | ||
|
||
export function pluck<K extends PropertyKey>(prop: K extends Placeholder ? never : K): { | ||
<U extends readonly unknown[] | Record<K, any>>(obj: Record<PropertyKey, U>): U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never; | ||
<U extends readonly unknown[] | Record<K, any>>(list: U[]): U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never; | ||
<U extends O[keyof O], UK extends keyof U, O extends Record<string, any>>(obj: K extends UK ? O : never): { [OK in keyof O]: O[OK][K] }; | ||
<U extends readonly unknown[] | Record<K, any>>(list: readonly U[]): U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never; | ||
}; | ||
export function pluck<U>(__: Placeholder, obj: Record<PropertyKey, U>): <K extends keyof U>(prop: K) => Array<U[K]>; | ||
export function pluck<U>(__: Placeholder, list: readonly U[]): <K extends keyof U>(prop: K) => Array<U[K]>; | ||
export function pluck<K extends keyof U, U>(prop: K, obj: Record<PropertyKey, U>): Array<U[K]>; | ||
export function pluck<K extends keyof U, U>(prop: K, list: readonly U[]): Array<U[K]>; | ||
export function pluck<U>(__: Placeholder, list: readonly U[]): <K extends keyof U>(prop: U extends readonly any[] ? number : K) => U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never; | ||
export function pluck<U extends O[keyof O], O extends Record<string, any>>(__: Placeholder, record: O): <K extends keyof U>(prop: K) => { [KK in keyof O]: O[KK][K] }; | ||
export function pluck< | ||
K extends keyof U, | ||
U extends C[keyof C extends string ? keyof C : number], | ||
C extends { [k: string]: Record<string, any> } | ReadonlyArray<Record<string, any> | readonly any[]> | ||
>(prop: K, collection: C): keyof C extends string ? { [CK in keyof C]: C[CK] extends Record<K, any> ? C[CK][K] : never } : Array<U[K]>; |