Skip to content

Commit

Permalink
Add type-level test to capture regression
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jun 28, 2024
1 parent 8e572cb commit 7e6e23a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test-d/inference.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,29 @@ expectType<Shape>(test(taggedUnion('_type', { rect, circle })));

expectType<Shape>(test(select(unknown, (_) => (Math.random() < 0.5 ? rect : circle))));

{
function takesShape(_d: Decoder<Shape>) {}

// Works
takesShape(
taggedUnion('_type', {
rect,
circle,
}),
);

// Should fail
expectError(
takesShape(
taggedUnion('_type', {
new: object({ _type: constant('new') }),
rect,
circle,
}),
),
);
}

interface Rect1 {
_type: 0;
x: number;
Expand Down

0 comments on commit 7e6e23a

Please sign in to comment.