forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintraExpressionInferencesInContextSensitive1.js
More file actions
145 lines (127 loc) · 4.09 KB
/
intraExpressionInferencesInContextSensitive1.js
File metadata and controls
145 lines (127 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//// [tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferencesInContextSensitive1.ts] ////
//// [intraExpressionInferencesInContextSensitive1.ts]
// https://github.com/microsoft/TypeScript/issues/60720
type Options<TContext> = {
onStart?: () => TContext;
onEnd?: (context: TContext) => void;
};
function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
return builder(true);
}
create((arg: boolean) => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => {},
}));
create(() => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => {},
}));
create((arg) => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => {},
}));
// https://github.com/microsoft/TypeScript/issues/57021
type Schema = Record<string, unknown>;
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly schema: TSchema;
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};
function step1<TSchema extends Schema = Schema>(
stepVal: StepFunction<TSchema>,
): StepFunction<TSchema> {
return stepVal;
}
const stepResult1 = step1((_something) => ({
schema: {
attribute: "anything",
},
toAnswers: (keys) => {
type Test = string extends typeof keys ? never : "true";
const test: Test = "true"; // ok
return { test };
},
}));
type StepFunction2<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly schema: (thing: number) => TSchema;
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};
function step2<TSchema extends Schema = Schema>(
stepVal: StepFunction2<TSchema>,
): StepFunction2<TSchema> {
return stepVal;
}
const stepResult2 = step2((_something) => ({
schema: (thing) => ({
attribute: "anything",
}),
toAnswers: (keys) => {
type Test = string extends typeof keys ? never : "true";
const test: Test = "true"; // ok
return { test };
},
}));
//// [intraExpressionInferencesInContextSensitive1.js]
"use strict";
// https://github.com/microsoft/TypeScript/issues/60720
function create(builder) {
return builder(true);
}
create(function (arg) { return ({
onStart: function () { return ({ time: new Date() }); },
onEnd: function (context) { },
}); });
create(function () { return ({
onStart: function () { return ({ time: new Date() }); },
onEnd: function (context) { },
}); });
create(function (arg) { return ({
onStart: function () { return ({ time: new Date() }); },
onEnd: function (context) { },
}); });
function step1(stepVal) {
return stepVal;
}
var stepResult1 = step1(function (_something) { return ({
schema: {
attribute: "anything",
},
toAnswers: function (keys) {
var test = "true"; // ok
return { test: test };
},
}); });
function step2(stepVal) {
return stepVal;
}
var stepResult2 = step2(function (_something) { return ({
schema: function (thing) { return ({
attribute: "anything",
}); },
toAnswers: function (keys) {
var test = "true"; // ok
return { test: test };
},
}); });
//// [intraExpressionInferencesInContextSensitive1.d.ts]
type Options<TContext> = {
onStart?: () => TContext;
onEnd?: (context: TContext) => void;
};
declare function create<TContext>(builder: (arg: boolean) => Options<TContext>): Options<TContext>;
type Schema = Record<string, unknown>;
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly schema: TSchema;
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};
declare function step1<TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>): StepFunction<TSchema>;
declare const stepResult1: StepFunction<{
attribute: string;
}>;
type StepFunction2<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly schema: (thing: number) => TSchema;
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};
declare function step2<TSchema extends Schema = Schema>(stepVal: StepFunction2<TSchema>): StepFunction2<TSchema>;
declare const stepResult2: StepFunction2<{
attribute: string;
}>;