Skip to content

Commit

Permalink
export isNonNullableKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonneal committed Oct 9, 2024
1 parent ff9b80e commit 0cf4cbf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions libs/ts-standard/src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function isNonNullable<T>(value: Nullable<T>): value is NonNullable<T> {
* Check if an object has `NonNullable` values for the given keys.
*
* @typeParam T - type of value to check
* @typeParam K - keys of `T` to check
*
* @param keys - to check values of
* @returns - function to check a given value
Expand All @@ -41,6 +42,10 @@ export function isNonNullable<T>(value: Nullable<T>): value is NonNullable<T> {
export function isNonNullableKeys<T, K extends keyof T = keyof T>(
keys: K[]
): (value: T) => value is NonNullableKeys<Pick<T, K>> & T {
/**
* @param value - value to check
* @returns whether value has non-nullable entries for all given keys
*/
return (value: T): value is NonNullableKeys<Pick<T, K>> & T =>
keys.every((key) => isNonNullable(value[key]));
}
2 changes: 1 addition & 1 deletion libs/ts-standard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* @module ts-standard
*/

export { isNonNullable } from './filter';
export { isNonNullable, isNonNullableKeys } from './filter';
export type { NonNullableKeys, Nullable, Opt } from './type';

0 comments on commit 0cf4cbf

Please sign in to comment.