Skip to content

Commit

Permalink
isMatching: add narrowing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gvergnaud committed Feb 25, 2025
1 parent f1af270 commit d5d1bf2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/is-matching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,16 @@ describe('isMatching', () => {
type t = Expect<Equal<typeof food, Food & { unknownProp: Error }>>;
}
});

it('should correctly narrow undiscriminated unions of objects.', () => {
type Input = { someProperty: string[] } | { this: 'is a string' };
const input = { someProperty: ['hello'] } satisfies Input as Input;

if (isMatching({ someProperty: P.array() }, input)) {
expect(input.someProperty).toEqual(['hello']);
type t = Expect<Equal<typeof input.someProperty, string[]>>;
} else {
throw new Error('pattern should match');
}
});
});

0 comments on commit d5d1bf2

Please sign in to comment.