Skip to content

Commit 23c6c33

Browse files
committed
add more tests
1 parent c61ea39 commit 23c6c33

8 files changed

+1571
-50
lines changed

tests/baselines/reference/InferFromReturnsInContextSensitive1.js

Lines changed: 215 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ create((arg) => ({
1717
onEnd: (context) => {},
1818
}));
1919

20+
create((arg) => ({
21+
onEnd: (context) => {},
22+
onStart: () => ({ time: new Date() }),
23+
}));
24+
2025
// https://github.com/microsoft/TypeScript/issues/57021
2126

2227
type Schema = Record<string, unknown>;
@@ -26,13 +31,13 @@ type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
2631
readonly toAnswers?: (keys: keyof TSchema) => unknown;
2732
};
2833

29-
function step1<TSchema extends Schema = Schema>(
34+
function step<TSchema extends Schema = Schema>(
3035
stepVal: StepFunction<TSchema>,
3136
): StepFunction<TSchema> {
3237
return stepVal;
3338
}
3439

35-
const stepResult1 = step1((_something) => ({
40+
const stepResult1 = step((_something) => ({
3641
schema: {
3742
attribute: "anything",
3843
},
@@ -42,6 +47,107 @@ const stepResult1 = step1((_something) => ({
4247
return { test };
4348
},
4449
}));
50+
51+
const stepResult2 = step((_something) => ({
52+
toAnswers: (keys) => {
53+
type Test = string extends typeof keys ? never : "true";
54+
const test: Test = "true"; // ok
55+
return { test };
56+
},
57+
schema: {
58+
attribute: "anything",
59+
},
60+
}));
61+
62+
type Fn1<T, T2> = (anything: unknown) => {
63+
stuff: T;
64+
consume: (arg: T) => (anything: unknown) => {
65+
stuff2: T2;
66+
consume2: (arg: T2) => void;
67+
};
68+
};
69+
70+
declare function test1<T, T2>(fn: Fn1<T, T2>): [T, T2];
71+
72+
const res1 = test1((_something) => ({
73+
stuff: "foo",
74+
consume: (arg) => {
75+
return (_something) => ({
76+
stuff2: 42,
77+
consume2: (arg2) => {},
78+
});
79+
},
80+
}));
81+
82+
const res2 = test1((_something) => ({
83+
consume: (arg) => {
84+
return (_something) => ({
85+
consume2: (arg2) => {},
86+
stuff2: 42,
87+
});
88+
},
89+
stuff: "foo",
90+
}));
91+
92+
const res3 = test1((_something) => ({
93+
stuff: "foo",
94+
consume: () => {
95+
return (_something) => ({
96+
stuff2: 42,
97+
consume2: (arg2) => {},
98+
});
99+
},
100+
}));
101+
102+
const res4 = test1((_something) => ({
103+
consume: () => {
104+
return (_something) => ({
105+
consume2: (arg2) => {},
106+
stuff2: 42,
107+
});
108+
},
109+
stuff: "foo",
110+
}));
111+
112+
const res5 = test1((_something) => ({
113+
stuff: "foo",
114+
consume: () => {
115+
return () => ({
116+
stuff2: 42,
117+
consume2: (arg2) => {},
118+
});
119+
},
120+
}));
121+
122+
const res6 = test1((_something) => ({
123+
consume: () => {
124+
return () => ({
125+
consume2: (arg2) => {},
126+
stuff2: 42,
127+
});
128+
},
129+
stuff: "foo",
130+
}));
131+
132+
const res7 = test1((_something) => ({
133+
stuff: "foo",
134+
consume: () => {
135+
return () => ({
136+
stuff2: 42,
137+
consume2: () => {},
138+
});
139+
},
140+
}));
141+
142+
const res8 = test1((_something) => ({
143+
consume: () => {
144+
return () => ({
145+
consume2: () => {},
146+
stuff2: 42,
147+
});
148+
},
149+
stuff: "foo",
150+
}));
45151

46152

47153
//// [InferFromReturnsInContextSensitive1.js]
@@ -54,10 +160,14 @@ create(function (arg) { return ({
54160
onStart: function () { return ({ time: new Date() }); },
55161
onEnd: function (context) { },
56162
}); });
57-
function step1(stepVal) {
163+
create(function (arg) { return ({
164+
onEnd: function (context) { },
165+
onStart: function () { return ({ time: new Date() }); },
166+
}); });
167+
function step(stepVal) {
58168
return stepVal;
59169
}
60-
var stepResult1 = step1(function (_something) { return ({
170+
var stepResult1 = step(function (_something) { return ({
61171
schema: {
62172
attribute: "anything",
63173
},
@@ -66,6 +176,87 @@ var stepResult1 = step1(function (_something) { return ({
66176
return { test: test };
67177
},
68178
}); });
179+
var stepResult2 = step(function (_something) { return ({
180+
toAnswers: function (keys) {
181+
var test = "true"; // ok
182+
return { test: test };
183+
},
184+
schema: {
185+
attribute: "anything",
186+
},
187+
}); });
188+
var res1 = test1(function (_something) { return ({
189+
stuff: "foo",
190+
consume: function (arg) {
191+
return function (_something) { return ({
192+
stuff2: 42,
193+
consume2: function (arg2) { },
194+
}); };
195+
},
196+
}); });
197+
var res2 = test1(function (_something) { return ({
198+
consume: function (arg) {
199+
return function (_something) { return ({
200+
consume2: function (arg2) { },
201+
stuff2: 42,
202+
}); };
203+
},
204+
stuff: "foo",
205+
}); });
206+
var res3 = test1(function (_something) { return ({
207+
stuff: "foo",
208+
consume: function () {
209+
return function (_something) { return ({
210+
stuff2: 42,
211+
consume2: function (arg2) { },
212+
}); };
213+
},
214+
}); });
215+
var res4 = test1(function (_something) { return ({
216+
consume: function () {
217+
return function (_something) { return ({
218+
consume2: function (arg2) { },
219+
stuff2: 42,
220+
}); };
221+
},
222+
stuff: "foo",
223+
}); });
224+
var res5 = test1(function (_something) { return ({
225+
stuff: "foo",
226+
consume: function () {
227+
return function () { return ({
228+
stuff2: 42,
229+
consume2: function (arg2) { },
230+
}); };
231+
},
232+
}); });
233+
var res6 = test1(function (_something) { return ({
234+
consume: function () {
235+
return function () { return ({
236+
consume2: function (arg2) { },
237+
stuff2: 42,
238+
}); };
239+
},
240+
stuff: "foo",
241+
}); });
242+
var res7 = test1(function (_something) { return ({
243+
stuff: "foo",
244+
consume: function () {
245+
return function () { return ({
246+
stuff2: 42,
247+
consume2: function () { },
248+
}); };
249+
},
250+
}); });
251+
var res8 = test1(function (_something) { return ({
252+
consume: function () {
253+
return function () { return ({
254+
consume2: function () { },
255+
stuff2: 42,
256+
}); };
257+
},
258+
stuff: "foo",
259+
}); });
69260

70261

71262
//// [InferFromReturnsInContextSensitive1.d.ts]
@@ -79,7 +270,26 @@ type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
79270
readonly schema: TSchema;
80271
readonly toAnswers?: (keys: keyof TSchema) => unknown;
81272
};
82-
declare function step1<TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>): StepFunction<TSchema>;
273+
declare function step<TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>): StepFunction<TSchema>;
83274
declare const stepResult1: StepFunction<{
84275
attribute: string;
85276
}>;
277+
declare const stepResult2: StepFunction<{
278+
attribute: string;
279+
}>;
280+
type Fn1<T, T2> = (anything: unknown) => {
281+
stuff: T;
282+
consume: (arg: T) => (anything: unknown) => {
283+
stuff2: T2;
284+
consume2: (arg: T2) => void;
285+
};
286+
};
287+
declare function test1<T, T2>(fn: Fn1<T, T2>): [T, T2];
288+
declare const res1: [string, number];
289+
declare const res2: [string, number];
290+
declare const res3: [string, number];
291+
declare const res4: [string, number];
292+
declare const res5: [string, number];
293+
declare const res6: [string, number];
294+
declare const res7: [string, number];
295+
declare const res8: [string, number];

0 commit comments

Comments
 (0)