From f8b43fbb7e79e84c055040ab5b65cf5ecb3fddf5 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Thu, 24 Sep 2020 08:46:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#47763=20[ramda]=20?= =?UTF-8?q?R.when=20does=20not=20always=20apply=20given=20function=20by=20?= =?UTF-8?q?@JalilArfaoui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/ramda/index.d.ts | 4 ++-- types/ramda/test/when-tests.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 2d3855f90d..69e8804ce8 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -2082,8 +2082,8 @@ export function view(lens: Lens, obj: T): U; * will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied, * the argument is returned as is. */ -export function when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): U; -export function when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => U; +export function when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): T | U; +export function when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => T | U; /** * Takes a spec object and a test object and returns true if the test satisfies the spec. diff --git a/types/ramda/test/when-tests.ts b/types/ramda/test/when-tests.ts index 43ba7ac354..56a37b3f01 100644 --- a/types/ramda/test/when-tests.ts +++ b/types/ramda/test/when-tests.ts @@ -11,4 +11,12 @@ import * as R from 'ramda'; ); const a: string = truncate('12345'); // => '12345' const b: string = truncate('0123456789ABC'); // => '0123456789…' + + const addOneIfNotNil = R.when( + R.complement(R.isNil), + R.add(1) + ); + + const nil: undefined = addOneIfNotNil(undefined); + const two: number = addOneIfNotNil(1); };