Skip to content

Commit dafed7f

Browse files
authored
Add tests for contextual param type assignment in nested return type inference scenarios (#62189)
1 parent 6618cf7 commit dafed7f

12 files changed

+1744
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//// [tests/cases/compiler/contextualParamTypeVsNestedReturnTypeInference1.ts] ////
2+
3+
=== contextualParamTypeVsNestedReturnTypeInference1.ts ===
4+
interface Effect<A> {
5+
>Effect : Symbol(Effect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 0))
6+
>A : Symbol(A, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 17))
7+
8+
_A: A;
9+
>_A : Symbol(Effect._A, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 21))
10+
>A : Symbol(A, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 17))
11+
}
12+
13+
declare function effectGen<AEff>(f: () => AEff): Effect<AEff>;
14+
>effectGen : Symbol(effectGen, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 2, 1))
15+
>AEff : Symbol(AEff, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 4, 27))
16+
>f : Symbol(f, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 4, 33))
17+
>AEff : Symbol(AEff, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 4, 27))
18+
>Effect : Symbol(Effect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 0))
19+
>AEff : Symbol(AEff, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 4, 27))
20+
21+
declare function effectFn<AEff, Args extends Array<any>>(
22+
>effectFn : Symbol(effectFn, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 4, 62))
23+
>AEff : Symbol(AEff, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 6, 26))
24+
>Args : Symbol(Args, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 6, 31))
25+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more)
26+
27+
body: (...args: Args) => unknown,
28+
>body : Symbol(body, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 6, 57))
29+
>args : Symbol(args, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 7, 9))
30+
>Args : Symbol(Args, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 6, 31))
31+
32+
): (...args: Args) => Effect<AEff>;
33+
>args : Symbol(args, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 8, 4))
34+
>Args : Symbol(Args, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 6, 31))
35+
>Effect : Symbol(Effect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 0))
36+
>AEff : Symbol(AEff, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 6, 26))
37+
38+
declare function layerEffect<S>(tag: Tag<S>, effect: Effect<S>): unknown;
39+
>layerEffect : Symbol(layerEffect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 8, 35))
40+
>S : Symbol(S, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 29))
41+
>tag : Symbol(tag, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 32))
42+
>Tag : Symbol(Tag, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 73))
43+
>S : Symbol(S, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 29))
44+
>effect : Symbol(effect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 44))
45+
>Effect : Symbol(Effect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 0, 0))
46+
>S : Symbol(S, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 29))
47+
48+
interface Tag<Type> {
49+
>Tag : Symbol(Tag, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 73))
50+
>Type : Symbol(Type, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 12, 14))
51+
52+
_Type: Type;
53+
>_Type : Symbol(Tag._Type, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 12, 21))
54+
>Type : Symbol(Type, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 12, 14))
55+
}
56+
57+
declare const Foo: Tag<{
58+
>Foo : Symbol(Foo, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 16, 13))
59+
>Tag : Symbol(Tag, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 10, 73))
60+
61+
fn: (a: string) => unknown;
62+
>fn : Symbol(fn, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 16, 24))
63+
>a : Symbol(a, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 17, 7))
64+
65+
}>;
66+
67+
layerEffect(
68+
>layerEffect : Symbol(layerEffect, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 8, 35))
69+
70+
Foo,
71+
>Foo : Symbol(Foo, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 16, 13))
72+
73+
effectGen(function () {
74+
>effectGen : Symbol(effectGen, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 2, 1))
75+
76+
return {
77+
fn: effectFn(function (a) {
78+
>fn : Symbol(fn, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 23, 12))
79+
>effectFn : Symbol(effectFn, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 4, 62))
80+
>a : Symbol(a, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 24, 29))
81+
82+
a; // string
83+
>a : Symbol(a, Decl(contextualParamTypeVsNestedReturnTypeInference1.ts, 24, 29))
84+
85+
}),
86+
};
87+
}),
88+
);
89+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//// [tests/cases/compiler/contextualParamTypeVsNestedReturnTypeInference1.ts] ////
2+
3+
=== contextualParamTypeVsNestedReturnTypeInference1.ts ===
4+
interface Effect<A> {
5+
_A: A;
6+
>_A : A
7+
> : ^
8+
}
9+
10+
declare function effectGen<AEff>(f: () => AEff): Effect<AEff>;
11+
>effectGen : <AEff>(f: () => AEff) => Effect<AEff>
12+
> : ^ ^^ ^^ ^^^^^
13+
>f : () => AEff
14+
> : ^^^^^^
15+
16+
declare function effectFn<AEff, Args extends Array<any>>(
17+
>effectFn : <AEff, Args extends Array<any>>(body: (...args: Args) => unknown) => (...args: Args) => Effect<AEff>
18+
> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^
19+
20+
body: (...args: Args) => unknown,
21+
>body : (...args: Args) => unknown
22+
> : ^^^^ ^^ ^^^^^
23+
>args : Args
24+
> : ^^^^
25+
26+
): (...args: Args) => Effect<AEff>;
27+
>args : Args
28+
> : ^^^^
29+
30+
declare function layerEffect<S>(tag: Tag<S>, effect: Effect<S>): unknown;
31+
>layerEffect : <S>(tag: Tag<S>, effect: Effect<S>) => unknown
32+
> : ^ ^^ ^^ ^^ ^^ ^^^^^
33+
>tag : Tag<S>
34+
> : ^^^^^^
35+
>effect : Effect<S>
36+
> : ^^^^^^^^^
37+
38+
interface Tag<Type> {
39+
_Type: Type;
40+
>_Type : Type
41+
> : ^^^^
42+
}
43+
44+
declare const Foo: Tag<{
45+
>Foo : Tag<{ fn: (a: string) => unknown; }>
46+
> : ^^^^^^^^^^ ^^^^
47+
48+
fn: (a: string) => unknown;
49+
>fn : (a: string) => unknown
50+
> : ^ ^^ ^^^^^
51+
>a : string
52+
> : ^^^^^^
53+
54+
}>;
55+
56+
layerEffect(
57+
>layerEffect( Foo, effectGen(function () { return { fn: effectFn(function (a) { a; // string }), }; }),) : unknown
58+
> : ^^^^^^^
59+
>layerEffect : <S>(tag: Tag<S>, effect: Effect<S>) => unknown
60+
> : ^ ^^ ^^ ^^ ^^ ^^^^^
61+
62+
Foo,
63+
>Foo : Tag<{ fn: (a: string) => unknown; }>
64+
> : ^^^^^^^^^^ ^^^^
65+
66+
effectGen(function () {
67+
>effectGen(function () { return { fn: effectFn(function (a) { a; // string }), }; }) : Effect<{ fn: (a: string) => Effect<unknown>; }>
68+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69+
>effectGen : <AEff>(f: () => AEff) => Effect<AEff>
70+
> : ^ ^^ ^^ ^^^^^
71+
>function () { return { fn: effectFn(function (a) { a; // string }), }; } : () => { fn: (a: string) => Effect<unknown>; }
72+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
74+
return {
75+
>{ fn: effectFn(function (a) { a; // string }), } : { fn: (a: string) => Effect<unknown>; }
76+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
78+
fn: effectFn(function (a) {
79+
>fn : (a: string) => Effect<unknown>
80+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81+
>effectFn(function (a) { a; // string }) : (a: string) => Effect<unknown>
82+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
>effectFn : <AEff, Args extends Array<any>>(body: (...args: Args) => unknown) => (...args: Args) => Effect<AEff>
84+
> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^
85+
>function (a) { a; // string } : (a: string) => void
86+
> : ^ ^^^^^^^^^^^^^^^^^
87+
>a : string
88+
> : ^^^^^^
89+
90+
a; // string
91+
>a : string
92+
> : ^^^^^^
93+
94+
}),
95+
};
96+
}),
97+
);
98+

0 commit comments

Comments
 (0)