Skip to content

Commit

Permalink
feat(mapnull): default type parameter U to be the same as T
Browse files Browse the repository at this point in the history
  • Loading branch information
djcsdy committed Mar 17, 2021
1 parent 2ae058e commit 140d439
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function mapFn<T, U>(f: (element: T) => U): (nullable: T | undefined | nu
*
* Useful as an alternative to {@link defaultValue} if the default value is
* expensive to compute. */
export function mapNull<T, U>(nullable: T | undefined | null, f: () => U): T | U {
export function mapNull<T, U = T>(nullable: T | undefined | null, f: () => U): T | U {
return nullable == null ? f() : nullable;
}

Expand All @@ -65,6 +65,6 @@ export function mapNull<T, U>(nullable: T | undefined | null, f: () => U): T | U
*
* Useful as an alternative to {@link defaultValueFn} if the default value is
* expensive to compute. */
export function mapNullFn<T, U>(f: () => U): (nullable: T | undefined | null) => T | U {
export function mapNullFn<T, U = T>(f: () => U): (nullable: T | undefined | null) => T | U {
return nullable => mapNull(nullable, f);
}

0 comments on commit 140d439

Please sign in to comment.