File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -55,4 +55,26 @@ describe('isMatching', () => {
55
55
) ;
56
56
}
57
57
} ) ;
58
+
59
+ it ( 'type inference should be precise without `as const`' , ( ) => {
60
+ type Pizza = { type : 'pizza' ; topping : string } ;
61
+ type Sandwich = { type : 'sandwich' ; condiments : string [ ] } ;
62
+ type Food = Pizza | Sandwich ;
63
+
64
+ const food = { type : 'pizza' , topping : 'cheese' } as Food ;
65
+
66
+ const isPizza = isMatching ( { type : 'pizza' } ) ;
67
+
68
+ if ( isPizza ( food ) ) {
69
+ type t = Expect < Equal < typeof food , Pizza > > ;
70
+ } else {
71
+ throw new Error ( 'Expected food to match the pizza pattern!' ) ;
72
+ }
73
+
74
+ if ( isMatching ( { type : 'pizza' } , food ) ) {
75
+ type t = Expect < Equal < typeof food , Pizza > > ;
76
+ } else {
77
+ throw new Error ( 'Expected food to match the pizza pattern!' ) ;
78
+ }
79
+ } ) ;
58
80
} ) ;
You can’t perform that action at this time.
0 commit comments