Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for type guards to partition function. #463

Open
kaciakmaciak opened this issue May 8, 2023 · 0 comments
Open

Adding support for type guards to partition function. #463

kaciakmaciak opened this issue May 8, 2023 · 0 comments

Comments

@kaciakmaciak
Copy link

Hi, could you please add support for the type guards for the partition function.

Use case:

function isNumber(value: unknown): value is number {
  return typeof value === 'number' && !Number.isNaN(value);
}

const someList: Array<unknown> = ['bla', 'foo', 'bar', 1, 2, 3, undefined, null];

const [numbers, others] = R.partition(isNumber, someList);

Currently, both numbers and others arrays type is unknown[]. It would be helpful if the numbers type is number[].

We used the patch package to temporarily fix this:

diff --git [a/node_modules/@types/ramda/index.d.ts](mailto:a/node_modules/@types/ramda/index.d.ts) [b/node_modules/@types/ramda/index.d.ts](mailto:b/node_modules/@types/ramda/index.d.ts)
index 402e443..0a3040f 100755
--- [a/node_modules/@types/ramda/index.d.ts](mailto:a/node_modules/@types/ramda/index.d.ts)
+++ [b/node_modules/@types/ramda/index.d.ts](mailto:b/node_modules/@types/ramda/index.d.ts)
@@ -3733,7 +3733,9 @@ export function partialRight<T>(fn: (...args: any[]) => T, args: unknown[]): (..
  * ```
  */
export function partition(fn: (a: string) => boolean, list: readonly string[]): [string[], string[]];
+export function partition<T, P>(fn: (a: T) => a is P, list: readonly T[]): [P[], T[]];
export function partition<T>(fn: (a: T) => boolean, list: readonly T[]): [T[], T[]];
+export function partition<T, P>(fn: (a: T) => a is P): (list: readonly T[]) => [P[], T[]];
export function partition<T>(fn: (a: T) => boolean): (list: readonly T[]) => [T[], T[]];
export function partition(fn: (a: string) => boolean): (list: readonly string[]) => [string[], string[]];

Please let us know if you need any help in this. Can help.

Cheers, Katarina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant