Skip to content

Commit 55c2da7

Browse files
committed
refactor: use NonEmptyArray
1 parent 3ddb12d commit 55c2da7

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/predicate/factory/allOf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { NonEmptyArray } from '../../types/arrays.js';
12
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
23
import type { IntersectionOf } from '../../types/utils.js';
34

45
/**
56
* All predicates must pass
67
*/
7-
export const allOf = <Predicates extends TypePredicateFn<unknown>[]>(
8+
export const allOf = <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(
89
...predicates: Predicates
910
): TypePredicateFn<IntersectionOf<InferPredicatesReturnType<Predicates>>> => {
1011
if (!predicates.length) {

src/predicate/factory/anyOf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { NonEmptyArray } from '../../types/arrays.js';
12
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
23
import type { UnionOf } from '../../types/utils.js';
34

45
/**
56
* Any predicate can pass
67
*/
7-
export const anyOf = <Predicates extends TypePredicateFn<unknown>[]>(
8+
export const anyOf = <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(
89
...predicates: Predicates
910
): TypePredicateFn<UnionOf<InferPredicatesReturnType<Predicates>>> => {
1011
if (!predicates.length) {

test/predicate/factory/allOf.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { isString } from '../../../src/predicate/isString.js';
77

88
describe('allOf()', () => {
99
it('Requires one or more type predicate function', () => {
10-
expect(() => allOf()).toThrow();
10+
expect(() => {
11+
// @ts-expect-error testing missing arguments
12+
allOf();
13+
}).toThrow();
1114
});
1215

1316
it('Returns a type predicate function', () => {

test/predicate/factory/anyOf.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { anyOf } from '../../../src/predicate/factory/anyOf.js';
44

55
describe('anyOf()', () => {
66
it('Requires one or more type predicate function', () => {
7-
expect(() => anyOf()).toThrow();
7+
expect(() => {
8+
// @ts-expect-error testing missing arguments
9+
return anyOf();
10+
}).toThrow();
811
});
912

1013
it('Returns a type predicate function', () => {

0 commit comments

Comments
 (0)