Skip to content

Commit be5f0fe

Browse files
authoredOct 14, 2022
Add an extra regression test for awaited unresolvable recursive union (#51167)
1 parent 2cb7e77 commit be5f0fe

4 files changed

+108
-3
lines changed
 

‎tests/baselines/reference/unresolvableSelfReferencingAwaitedUnion.errors.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts(9,32): error TS2322: Type 'SimpleType' is not assignable to type 'T'.
22
'T' could be instantiated with an arbitrary type which could be unrelated to 'SimpleType'.
33
tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts(16,19): error TS1062: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method.
4+
tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts(29,30): error TS1062: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method.
45

56

6-
==== tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts (2 errors) ====
7+
==== tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts (3 errors) ====
78
// repro #49646
89

910
type EnvFunction = <T>() => T;
@@ -27,4 +28,20 @@ tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts(16,19): error TS
2728
~~~~~~~~~~~
2829
!!! error TS1062: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method.
2930
}
31+
32+
// repro #42948
33+
34+
type EffectResult =
35+
| (() => EffectResult)
36+
| Promise<EffectResult>;
37+
38+
export async function handleEffectResult(result: EffectResult) {
39+
if (result instanceof Function) {
40+
await handleEffectResult(result());
41+
} else if (result instanceof Promise) {
42+
await handleEffectResult(await result);
43+
~~~~~~~~~~~~
44+
!!! error TS1062: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method.
45+
}
46+
}
3047

‎tests/baselines/reference/unresolvableSelfReferencingAwaitedUnion.symbols

+37-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type EnvFunction = <T>() => T;
88

99
type SimpleType = string | Promise<SimpleType>;
1010
>SimpleType : Symbol(SimpleType, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 30))
11-
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
11+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
1212
>SimpleType : Symbol(SimpleType, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 30))
1313

1414
declare const simple: SimpleType;
@@ -24,7 +24,7 @@ const env: EnvFunction = () => simple;
2424

2525
type T1 = 1 | Promise<T1> | T1[];
2626
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38))
27-
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
27+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
2828
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38))
2929
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38))
3030

@@ -38,3 +38,38 @@ export async function myFunction(param: T1) {
3838
>param : Symbol(param, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 14, 33))
3939
}
4040

41+
// repro #42948
42+
43+
type EffectResult =
44+
>EffectResult : Symbol(EffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 16, 1))
45+
46+
| (() => EffectResult)
47+
>EffectResult : Symbol(EffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 16, 1))
48+
49+
| Promise<EffectResult>;
50+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
51+
>EffectResult : Symbol(EffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 16, 1))
52+
53+
export async function handleEffectResult(result: EffectResult) {
54+
>handleEffectResult : Symbol(handleEffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 22, 26))
55+
>result : Symbol(result, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 24, 41))
56+
>EffectResult : Symbol(EffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 16, 1))
57+
58+
if (result instanceof Function) {
59+
>result : Symbol(result, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 24, 41))
60+
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
61+
62+
await handleEffectResult(result());
63+
>handleEffectResult : Symbol(handleEffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 22, 26))
64+
>result : Symbol(result, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 24, 41))
65+
66+
} else if (result instanceof Promise) {
67+
>result : Symbol(result, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 24, 41))
68+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
69+
70+
await handleEffectResult(await result);
71+
>handleEffectResult : Symbol(handleEffectResult, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 22, 26))
72+
>result : Symbol(result, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 24, 41))
73+
}
74+
}
75+

‎tests/baselines/reference/unresolvableSelfReferencingAwaitedUnion.types

+38
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,41 @@ export async function myFunction(param: T1) {
3030
>param : T1
3131
}
3232

33+
// repro #42948
34+
35+
type EffectResult =
36+
>EffectResult : (() => EffectResult) | Promise<EffectResult>
37+
38+
| (() => EffectResult)
39+
| Promise<EffectResult>;
40+
41+
export async function handleEffectResult(result: EffectResult) {
42+
>handleEffectResult : (result: EffectResult) => Promise<void>
43+
>result : EffectResult
44+
45+
if (result instanceof Function) {
46+
>result instanceof Function : boolean
47+
>result : EffectResult
48+
>Function : FunctionConstructor
49+
50+
await handleEffectResult(result());
51+
>await handleEffectResult(result()) : void
52+
>handleEffectResult(result()) : Promise<void>
53+
>handleEffectResult : (result: EffectResult) => Promise<void>
54+
>result() : EffectResult
55+
>result : () => EffectResult
56+
57+
} else if (result instanceof Promise) {
58+
>result instanceof Promise : boolean
59+
>result : Promise<EffectResult>
60+
>Promise : PromiseConstructor
61+
62+
await handleEffectResult(await result);
63+
>await handleEffectResult(await result) : void
64+
>handleEffectResult(await result) : Promise<void>
65+
>handleEffectResult : (result: EffectResult) => Promise<void>
66+
>await result : () => EffectResult
67+
>result : Promise<EffectResult>
68+
}
69+
}
70+

‎tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @noEmit: true
2+
// @lib: esnext
23

34
// repro #49646
45

@@ -17,3 +18,17 @@ type T1 = 1 | Promise<T1> | T1[];
1718
export async function myFunction(param: T1) {
1819
const awaited = await param
1920
}
21+
22+
// repro #42948
23+
24+
type EffectResult =
25+
| (() => EffectResult)
26+
| Promise<EffectResult>;
27+
28+
export async function handleEffectResult(result: EffectResult) {
29+
if (result instanceof Function) {
30+
await handleEffectResult(result());
31+
} else if (result instanceof Promise) {
32+
await handleEffectResult(await result);
33+
}
34+
}

0 commit comments

Comments
 (0)