Skip to content

Commit c61ea39

Browse files
committed
split tests
1 parent c671b45 commit c61ea39

8 files changed

Lines changed: 535 additions & 479 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] ////
2+
3+
//// [InferFromReturnsInContextSensitive1.ts]
4+
// https://github.com/microsoft/TypeScript/issues/60720
5+
6+
type Options<TContext> = {
7+
onStart?: () => TContext;
8+
onEnd?: (context: TContext) => void;
9+
};
10+
11+
function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
12+
return builder(true);
13+
}
14+
15+
create((arg) => ({
16+
onStart: () => ({ time: new Date() }),
17+
onEnd: (context) => {},
18+
}));
19+
20+
// https://github.com/microsoft/TypeScript/issues/57021
21+
22+
type Schema = Record<string, unknown>;
23+
24+
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
25+
readonly schema: TSchema;
26+
readonly toAnswers?: (keys: keyof TSchema) => unknown;
27+
};
28+
29+
function step1<TSchema extends Schema = Schema>(
30+
stepVal: StepFunction<TSchema>,
31+
): StepFunction<TSchema> {
32+
return stepVal;
33+
}
34+
35+
const stepResult1 = step1((_something) => ({
36+
schema: {
37+
attribute: "anything",
38+
},
39+
toAnswers: (keys) => {
40+
type Test = string extends typeof keys ? never : "true";
41+
const test: Test = "true"; // ok
42+
return { test };
43+
},
44+
}));
45+
46+
47+
//// [InferFromReturnsInContextSensitive1.js]
48+
"use strict";
49+
// https://github.com/microsoft/TypeScript/issues/60720
50+
function create(builder) {
51+
return builder(true);
52+
}
53+
create(function (arg) { return ({
54+
onStart: function () { return ({ time: new Date() }); },
55+
onEnd: function (context) { },
56+
}); });
57+
function step1(stepVal) {
58+
return stepVal;
59+
}
60+
var stepResult1 = step1(function (_something) { return ({
61+
schema: {
62+
attribute: "anything",
63+
},
64+
toAnswers: function (keys) {
65+
var test = "true"; // ok
66+
return { test: test };
67+
},
68+
}); });
69+
70+
71+
//// [InferFromReturnsInContextSensitive1.d.ts]
72+
type Options<TContext> = {
73+
onStart?: () => TContext;
74+
onEnd?: (context: TContext) => void;
75+
};
76+
declare function create<TContext>(builder: (arg: boolean) => Options<TContext>): Options<TContext>;
77+
type Schema = Record<string, unknown>;
78+
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
79+
readonly schema: TSchema;
80+
readonly toAnswers?: (keys: keyof TSchema) => unknown;
81+
};
82+
declare function step1<TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>): StepFunction<TSchema>;
83+
declare const stepResult1: StepFunction<{
84+
attribute: string;
85+
}>;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] ////
2+
3+
=== InferFromReturnsInContextSensitive1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/60720
5+
6+
type Options<TContext> = {
7+
>Options : Symbol(Options, Decl(InferFromReturnsInContextSensitive1.ts, 0, 0))
8+
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13))
9+
10+
onStart?: () => TContext;
11+
>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 2, 26))
12+
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13))
13+
14+
onEnd?: (context: TContext) => void;
15+
>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 3, 27))
16+
>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 4, 11))
17+
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13))
18+
19+
};
20+
21+
function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
22+
>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2))
23+
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 7, 16))
24+
>builder : Symbol(builder, Decl(InferFromReturnsInContextSensitive1.ts, 7, 26))
25+
>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 7, 36))
26+
>Options : Symbol(Options, Decl(InferFromReturnsInContextSensitive1.ts, 0, 0))
27+
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 7, 16))
28+
29+
return builder(true);
30+
>builder : Symbol(builder, Decl(InferFromReturnsInContextSensitive1.ts, 7, 26))
31+
}
32+
33+
create((arg) => ({
34+
>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2))
35+
>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 11, 8))
36+
37+
onStart: () => ({ time: new Date() }),
38+
>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 11, 18))
39+
>time : Symbol(time, Decl(InferFromReturnsInContextSensitive1.ts, 12, 19))
40+
>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --))
41+
42+
onEnd: (context) => {},
43+
>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 12, 40))
44+
>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 13, 10))
45+
46+
}));
47+
48+
// https://github.com/microsoft/TypeScript/issues/57021
49+
50+
type Schema = Record<string, unknown>;
51+
>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4))
52+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
53+
54+
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
55+
>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38))
56+
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18))
57+
>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4))
58+
>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4))
59+
>anything : Symbol(anything, Decl(InferFromReturnsInContextSensitive1.ts, 20, 54))
60+
61+
readonly schema: TSchema;
62+
>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 77))
63+
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18))
64+
65+
readonly toAnswers?: (keys: keyof TSchema) => unknown;
66+
>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 21, 27))
67+
>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 22, 24))
68+
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18))
69+
70+
};
71+
72+
function step1<TSchema extends Schema = Schema>(
73+
>step1 : Symbol(step1, Decl(InferFromReturnsInContextSensitive1.ts, 23, 2))
74+
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15))
75+
>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4))
76+
>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4))
77+
78+
stepVal: StepFunction<TSchema>,
79+
>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48))
80+
>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38))
81+
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15))
82+
83+
): StepFunction<TSchema> {
84+
>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38))
85+
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15))
86+
87+
return stepVal;
88+
>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48))
89+
}
90+
91+
const stepResult1 = step1((_something) => ({
92+
>stepResult1 : Symbol(stepResult1, Decl(InferFromReturnsInContextSensitive1.ts, 31, 5))
93+
>step1 : Symbol(step1, Decl(InferFromReturnsInContextSensitive1.ts, 23, 2))
94+
>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 31, 27))
95+
96+
schema: {
97+
>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 31, 44))
98+
99+
attribute: "anything",
100+
>attribute : Symbol(attribute, Decl(InferFromReturnsInContextSensitive1.ts, 32, 11))
101+
102+
},
103+
toAnswers: (keys) => {
104+
>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 34, 4))
105+
>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 14))
106+
107+
type Test = string extends typeof keys ? never : "true";
108+
>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24))
109+
>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 14))
110+
111+
const test: Test = "true"; // ok
112+
>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 37, 9))
113+
>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24))
114+
115+
return { test };
116+
>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 38, 12))
117+
118+
},
119+
}));
120+
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] ////
2+
3+
=== InferFromReturnsInContextSensitive1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/60720
5+
6+
type Options<TContext> = {
7+
>Options : Options<TContext>
8+
> : ^^^^^^^^^^^^^^^^^
9+
10+
onStart?: () => TContext;
11+
>onStart : (() => TContext) | undefined
12+
> : ^^^^^^^ ^^^^^^^^^^^^^
13+
14+
onEnd?: (context: TContext) => void;
15+
>onEnd : ((context: TContext) => void) | undefined
16+
> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^
17+
>context : TContext
18+
> : ^^^^^^^^
19+
20+
};
21+
22+
function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
23+
>create : <TContext>(builder: (arg: boolean) => Options<TContext>) => Options<TContext>
24+
> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^
25+
>builder : (arg: boolean) => Options<TContext>
26+
> : ^ ^^ ^^^^^
27+
>arg : boolean
28+
> : ^^^^^^^
29+
30+
return builder(true);
31+
>builder(true) : Options<TContext>
32+
> : ^^^^^^^^^^^^^^^^^
33+
>builder : (arg: boolean) => Options<TContext>
34+
> : ^ ^^ ^^^^^
35+
>true : true
36+
> : ^^^^
37+
}
38+
39+
create((arg) => ({
40+
>create((arg) => ({ onStart: () => ({ time: new Date() }), onEnd: (context) => {},})) : Options<{ time: Date; }>
41+
> : ^^^^^^^^^^^^^^^^^^^^^^^^
42+
>create : <TContext>(builder: (arg: boolean) => Options<TContext>) => Options<TContext>
43+
> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^
44+
>(arg) => ({ onStart: () => ({ time: new Date() }), onEnd: (context) => {},}) : (arg: boolean) => { onStart: () => { time: Date; }; onEnd: (context: { time: Date; }) => void; }
45+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
>arg : boolean
47+
> : ^^^^^^^
48+
>({ onStart: () => ({ time: new Date() }), onEnd: (context) => {},}) : { onStart: () => { time: Date; }; onEnd: (context: { time: Date; }) => void; }
49+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
>{ onStart: () => ({ time: new Date() }), onEnd: (context) => {},} : { onStart: () => { time: Date; }; onEnd: (context: { time: Date; }) => void; }
51+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
53+
onStart: () => ({ time: new Date() }),
54+
>onStart : () => { time: Date; }
55+
> : ^^^^^^^^^^^^^^^^^^^^^
56+
>() => ({ time: new Date() }) : () => { time: Date; }
57+
> : ^^^^^^^^^^^^^^^^^^^^^
58+
>({ time: new Date() }) : { time: Date; }
59+
> : ^^^^^^^^^^^^^^^
60+
>{ time: new Date() } : { time: Date; }
61+
> : ^^^^^^^^^^^^^^^
62+
>time : Date
63+
> : ^^^^
64+
>new Date() : Date
65+
> : ^^^^
66+
>Date : DateConstructor
67+
> : ^^^^^^^^^^^^^^^
68+
69+
onEnd: (context) => {},
70+
>onEnd : (context: { time: Date; }) => void
71+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
>(context) => {} : (context: { time: Date; }) => void
73+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
>context : { time: Date; }
75+
> : ^^^^^^^^^^^^^^^
76+
77+
}));
78+
79+
// https://github.com/microsoft/TypeScript/issues/57021
80+
81+
type Schema = Record<string, unknown>;
82+
>Schema : Schema
83+
> : ^^^^^^
84+
85+
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
86+
>StepFunction : StepFunction<TSchema>
87+
> : ^^^^^^^^^^^^^^^^^^^^^
88+
>anything : unknown
89+
> : ^^^^^^^
90+
91+
readonly schema: TSchema;
92+
>schema : TSchema
93+
> : ^^^^^^^
94+
95+
readonly toAnswers?: (keys: keyof TSchema) => unknown;
96+
>toAnswers : ((keys: keyof TSchema) => unknown) | undefined
97+
> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^
98+
>keys : keyof TSchema
99+
> : ^^^^^^^^^^^^^
100+
101+
};
102+
103+
function step1<TSchema extends Schema = Schema>(
104+
>step1 : <TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>) => StepFunction<TSchema>
105+
> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^
106+
107+
stepVal: StepFunction<TSchema>,
108+
>stepVal : StepFunction<TSchema>
109+
> : ^^^^^^^^^^^^^^^^^^^^^
110+
111+
): StepFunction<TSchema> {
112+
return stepVal;
113+
>stepVal : StepFunction<TSchema>
114+
> : ^^^^^^^^^^^^^^^^^^^^^
115+
}
116+
117+
const stepResult1 = step1((_something) => ({
118+
>stepResult1 : StepFunction<{ attribute: string; }>
119+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120+
>step1((_something) => ({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },})) : StepFunction<{ attribute: string; }>
121+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122+
>step1 : <TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>) => StepFunction<TSchema>
123+
> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^
124+
>(_something) => ({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },}) : (_something: unknown) => { schema: { attribute: string; }; toAnswers: (keys: "attribute") => { test: "true"; }; }
125+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126+
>_something : unknown
127+
> : ^^^^^^^
128+
>({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },}) : { schema: { attribute: string; }; toAnswers: (keys: "attribute") => { test: "true"; }; }
129+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130+
>{ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },} : { schema: { attribute: string; }; toAnswers: (keys: "attribute") => { test: "true"; }; }
131+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133+
schema: {
134+
>schema : { attribute: string; }
135+
> : ^^^^^^^^^^^^^^^^^^^^^^
136+
>{ attribute: "anything", } : { attribute: string; }
137+
> : ^^^^^^^^^^^^^^^^^^^^^^
138+
139+
attribute: "anything",
140+
>attribute : string
141+
> : ^^^^^^
142+
>"anything" : "anything"
143+
> : ^^^^^^^^^^
144+
145+
},
146+
toAnswers: (keys) => {
147+
>toAnswers : (keys: "attribute") => { test: "true"; }
148+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149+
>(keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; } : (keys: "attribute") => { test: "true"; }
150+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+
>keys : "attribute"
152+
> : ^^^^^^^^^^^
153+
154+
type Test = string extends typeof keys ? never : "true";
155+
>Test : "true"
156+
> : ^^^^^^
157+
>keys : "attribute"
158+
> : ^^^^^^^^^^^
159+
160+
const test: Test = "true"; // ok
161+
>test : "true"
162+
> : ^^^^^^
163+
>"true" : "true"
164+
> : ^^^^^^
165+
166+
return { test };
167+
>{ test } : { test: "true"; }
168+
> : ^^^^^^^^^^^^^^^^^
169+
>test : "true"
170+
> : ^^^^^^
171+
172+
},
173+
}));
174+

0 commit comments

Comments
 (0)