Skip to content

Commit

Permalink
Add additional test, checking type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
vidhill committed Nov 11, 2024
1 parent ae197c2 commit 3faee03
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/array-partition/index.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const test2: [string[], number[]] = partition(['a', 2, 3, '3'], (x): x is string
});
const test3: [number[], number[]] = partition([1, 2, 3, 4], x => typeof x == 'string');
const test4: [unknown[], unknown[]] = partition([], n => n > 3); // [[], []]
const test5: [boolean[], number[]] = partition([1, true, 2, 3, true], isBoolean);

// Not OK
// @ts-expect-error
Expand All @@ -21,3 +22,7 @@ partition(null, n => n > 1);
partition(undefined, n => n > 1);
// @ts-expect-error
partition([1, 5, 2, 4, 3], n => n > 3, "a");

function isBoolean(x: unknown): x is boolean {
return typeof x === 'boolean';
}

0 comments on commit 3faee03

Please sign in to comment.