Skip to content

Commit a3c5821

Browse files
committed
add an extra test case
1 parent d1e4079 commit a3c5821

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

tests/baselines/reference/narrowingNoInfer1.symbols

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,40 @@ const something = map(m, (_) =>
6161

6262
);
6363

64+
declare function test2<T1, T2>(a: T1, b: T2, cb: (thing: NoInfer<T1> | NoInfer<T2>) => void): void;
65+
>test2 : Symbol(test2, Decl(narrowingNoInfer1.ts, 15, 2))
66+
>T1 : Symbol(T1, Decl(narrowingNoInfer1.ts, 17, 23))
67+
>T2 : Symbol(T2, Decl(narrowingNoInfer1.ts, 17, 26))
68+
>a : Symbol(a, Decl(narrowingNoInfer1.ts, 17, 31))
69+
>T1 : Symbol(T1, Decl(narrowingNoInfer1.ts, 17, 23))
70+
>b : Symbol(b, Decl(narrowingNoInfer1.ts, 17, 37))
71+
>T2 : Symbol(T2, Decl(narrowingNoInfer1.ts, 17, 26))
72+
>cb : Symbol(cb, Decl(narrowingNoInfer1.ts, 17, 44))
73+
>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 17, 50))
74+
>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --))
75+
>T1 : Symbol(T1, Decl(narrowingNoInfer1.ts, 17, 23))
76+
>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --))
77+
>T2 : Symbol(T2, Decl(narrowingNoInfer1.ts, 17, 26))
78+
79+
test2({ type: 'a' as const }, { type: 'b' as const }, (thing) => {
80+
>test2 : Symbol(test2, Decl(narrowingNoInfer1.ts, 15, 2))
81+
>type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 7))
82+
>const : Symbol(const)
83+
>type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 31))
84+
>const : Symbol(const)
85+
>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55))
86+
87+
if (thing.type === "a") {
88+
>thing.type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 7), Decl(narrowingNoInfer1.ts, 19, 31))
89+
>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55))
90+
>type : Symbol(type, Decl(narrowingNoInfer1.ts, 19, 7), Decl(narrowingNoInfer1.ts, 19, 31))
91+
92+
thing;
93+
>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55))
94+
95+
} else {
96+
thing;
97+
>thing : Symbol(thing, Decl(narrowingNoInfer1.ts, 19, 55))
98+
}
99+
});
100+

tests/baselines/reference/narrowingNoInfer1.types

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,64 @@ const something = map(m, (_) =>
9696

9797
);
9898

99+
declare function test2<T1, T2>(a: T1, b: T2, cb: (thing: NoInfer<T1> | NoInfer<T2>) => void): void;
100+
>test2 : <T1, T2>(a: T1, b: T2, cb: (thing: NoInfer<T1> | NoInfer<T2>) => void) => void
101+
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
102+
>a : T1
103+
> : ^^
104+
>b : T2
105+
> : ^^
106+
>cb : (thing: NoInfer<T1> | NoInfer<T2>) => void
107+
> : ^ ^^ ^^^^^
108+
>thing : NoInfer<T1> | NoInfer<T2>
109+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
110+
111+
test2({ type: 'a' as const }, { type: 'b' as const }, (thing) => {
112+
>test2({ type: 'a' as const }, { type: 'b' as const }, (thing) => { if (thing.type === "a") { thing; } else { thing; }}) : void
113+
> : ^^^^
114+
>test2 : <T1, T2>(a: T1, b: T2, cb: (thing: NoInfer<T1> | NoInfer<T2>) => void) => void
115+
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^
116+
>{ type: 'a' as const } : { type: "a"; }
117+
> : ^^^^^^^^^^^^^^
118+
>type : "a"
119+
> : ^^^
120+
>'a' as const : "a"
121+
> : ^^^
122+
>'a' : "a"
123+
> : ^^^
124+
>{ type: 'b' as const } : { type: "b"; }
125+
> : ^^^^^^^^^^^^^^
126+
>type : "b"
127+
> : ^^^
128+
>'b' as const : "b"
129+
> : ^^^
130+
>'b' : "b"
131+
> : ^^^
132+
>(thing) => { if (thing.type === "a") { thing; } else { thing; }} : (thing: NoInfer<{ type: "a"; }> | NoInfer<{ type: "b"; }>) => void
133+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134+
>thing : NoInfer<{ type: "a"; }> | NoInfer<{ type: "b"; }>
135+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136+
137+
if (thing.type === "a") {
138+
>thing.type === "a" : boolean
139+
> : ^^^^^^^
140+
>thing.type : "a" | "b"
141+
> : ^^^^^^^^^
142+
>thing : NoInfer<{ type: "a"; }> | NoInfer<{ type: "b"; }>
143+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144+
>type : "a" | "b"
145+
> : ^^^^^^^^^
146+
>"a" : "a"
147+
> : ^^^
148+
149+
thing;
150+
>thing : NoInfer<{ type: "a"; }>
151+
> : ^^^^^^^^^^^^^^^^^^^^^^^
152+
153+
} else {
154+
thing;
155+
>thing : NoInfer<{ type: "b"; }>
156+
> : ^^^^^^^^^^^^^^^^^^^^^^^
157+
}
158+
});
159+

tests/cases/compiler/narrowingNoInfer1.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ function map<A, B>(items: readonly A[], f: (a: NoInfer<A>) => B) {
1717
const something = map(m, (_) =>
1818
_.result._tag === "a" ? { ..._, result: _.result } : null,
1919
);
20+
21+
declare function test2<T1, T2>(a: T1, b: T2, cb: (thing: NoInfer<T1> | NoInfer<T2>) => void): void;
22+
23+
test2({ type: 'a' as const }, { type: 'b' as const }, (thing) => {
24+
if (thing.type === "a") {
25+
thing;
26+
} else {
27+
thing;
28+
}
29+
});

0 commit comments

Comments
 (0)