Skip to content

Commit

Permalink
fix: fixed shape#array types (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Jul 7, 2022
1 parent 5f26e32 commit 43016a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/Shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Shapes {
return new UnionValidator(validators);
}

public array<T>(validator: BaseValidator<T>) {
public array<T extends unknown[]>(validator: BaseValidator<T[number]>) {
return new ArrayValidator(validator);
}

Expand Down
6 changes: 4 additions & 2 deletions tests/validators/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ describe('BaseValidator', () => {
const numberArrayPredicate = s.number.array;
const input = [1, 2, 3];

test('GIVEN an array of string THEN returns the given value', () => {
test('GIVEN an array of number THEN returns the given value', () => {
expect<number[]>(numberArrayPredicate.parse(input)).toStrictEqual(input);
});

test('GIVEN s.string.array THEN returns s.array(s.string)', () => {
test('GIVEN s.number.array THEN returns s.array(s.number)', () => {
const arrayNumberPredicate = s.array(s.number);

expect<number[]>(numberArrayPredicate.parse([1])).toStrictEqual([1]);
expect<number[]>(arrayNumberPredicate.parse([1, 2, 3])).toStrictEqual([1, 2, 3]);
expectClonedValidator(numberArrayPredicate, arrayNumberPredicate);
});
});
Expand Down

0 comments on commit 43016a0

Please sign in to comment.