Skip to content

Commit 9953157

Browse files
committed
feat(nonenull): improve type signature for noneNull
It is now possible to pass a tuple type to noneNull and get back the appropriate tuple type. BREAKING CHANGE: The type parameter to noneNull has changed to the type of the array itself, not the type of its elements. The behaviour of the function is unchanged. Callers that specify an explicit type parameter will need to be updated.
1 parent 1821049 commit 9953157

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,10 @@ export function concatMapFn<T, U>(
602602
return array => concatMap(array, f);
603603
}
604604

605-
export function noneNull<T>(array: ArrayLike<T | null>): ArrayLike<T> | null {
606-
return any(array, isNull) ? null : (array as ArrayLike<T>);
605+
export type NoneNull<T extends ArrayLike<unknown>> = {[K in keyof T]: NonNullable<T[K]>};
606+
607+
export function noneNull<T extends ArrayLike<unknown>>(array: T): NoneNull<T> | null {
608+
return any(array, isNull) ? null : (array as NoneNull<T>);
607609
}
608610

609611
export function scan<T, U>(

0 commit comments

Comments
 (0)