Skip to content

Commit c29601c

Browse files
committed
add tests
1 parent c7f90c9 commit c29601c

File tree

4 files changed

+2041
-0
lines changed

4 files changed

+2041
-0
lines changed
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
thislessFunctionsNotContextSensitive1.ts(25,3): error TS2345: Argument of type 'false' is not assignable to parameter of type 'true'.
2+
thislessFunctionsNotContextSensitive1.ts(143,13): error TS2345: Argument of type '"value"' is not assignable to parameter of type 'never'.
3+
thislessFunctionsNotContextSensitive1.ts(176,3): error TS2820: Type '"$test6"' is not assignable to type 'ExtractFields<{ target: "$test6"; data1: { $test1: number; $test2: null; }; data2: { $test3: {}; $test4: () => void; $test5(): void; }; }> | undefined'. Did you mean '"$test4"'?
4+
5+
6+
==== thislessFunctionsNotContextSensitive1.ts (3 errors) ====
7+
// https://github.com/microsoft/TypeScript/issues/62204
8+
9+
declare function TestConfig<const TConfig extends { a?: any; b?: any; c?: any }>(
10+
config: TConfig,
11+
test: keyof Omit<TConfig, "a" | "b"> extends never ? true : false,
12+
): void;
13+
14+
TestConfig(
15+
{
16+
a: "hello",
17+
b: function () {
18+
return 123;
19+
},
20+
},
21+
true,
22+
);
23+
24+
TestConfig(
25+
{
26+
a: "hello",
27+
b: function () {
28+
return 123;
29+
},
30+
},
31+
false, // error
32+
~~~~~
33+
!!! error TS2345: Argument of type 'false' is not assignable to parameter of type 'true'.
34+
);
35+
36+
// https://github.com/microsoft/TypeScript/issues/60986
37+
interface SubscribeFieldOptions<Event> {
38+
subscribe: () => Event;
39+
resolve: (event: Event) => number;
40+
}
41+
42+
declare function defineOptions<Event>(
43+
options: SubscribeFieldOptions<Event>,
44+
): void;
45+
46+
defineOptions({
47+
resolve: (event) => event, // number
48+
subscribe() {
49+
return 123;
50+
},
51+
});
52+
53+
defineOptions({
54+
resolve: (event) => event, // number
55+
subscribe: function () {
56+
return 123;
57+
},
58+
});
59+
60+
// https://github.com/microsoft/TypeScript/issues/58630
61+
62+
export type StateFunction<State> = (s: State, ...args: any[]) => any;
63+
64+
export type VuexStoreOptions<State, Modules> = {
65+
state?: State | (() => State) | { (): State };
66+
mutations?: Record<string, StateFunction<State>>;
67+
modules?: {
68+
[k in keyof Modules]: VuexStoreOptions<Modules[k], never>;
69+
};
70+
};
71+
72+
export function createStore<
73+
State extends Record<string, unknown>,
74+
Modules extends Record<string, Record<string, unknown>>,
75+
>(options: VuexStoreOptions<State, Modules>) {}
76+
77+
const store = createStore({
78+
state() {
79+
return { bar2: 1 };
80+
},
81+
mutations: { inc: (state123) => state123.bar2++ },
82+
modules: {
83+
foo: {
84+
state() {
85+
return { bar2: 1 };
86+
},
87+
mutations: { inc: (state) => state.bar2++ },
88+
},
89+
},
90+
});
91+
92+
// https://github.com/microsoft/TypeScript/issues/57572
93+
94+
type C = <Methods, Attached = (methods: Methods) => void>(options: {
95+
methods: Methods;
96+
attached: Attached;
97+
}) => any;
98+
99+
var Component: C = () => {};
100+
101+
Component({
102+
attached(methods) {
103+
methods.bbb(); // ok
104+
},
105+
methods: {
106+
bbb() {},
107+
},
108+
});
109+
110+
Component({
111+
attached(methods) {
112+
methods.bbb(); // ok
113+
},
114+
methods: {
115+
bbb: () => {},
116+
},
117+
});
118+
119+
// https://github.com/microsoft/TypeScript/issues/56067
120+
121+
declare function create56067<
122+
State extends Record<string, any>,
123+
Data extends Record<string, any>,
124+
Actions extends (state: State, data: Data) => Record<string, any>,
125+
>(args: { getState: () => State; actions: Actions; getData: () => Data }): void;
126+
127+
create56067({
128+
getState() {
129+
return { a: 1 };
130+
},
131+
getData: () => {
132+
return { b: 2 };
133+
},
134+
actions(state, data) {
135+
state // { a: number }
136+
data; // { b: number }
137+
return {
138+
z: 1,
139+
};
140+
},
141+
});
142+
143+
// https://github.com/microsoft/TypeScript/issues/55489
144+
type NonStringIterable<T> =
145+
T extends string ? never : T extends Iterable<any> ? T : never;
146+
147+
declare function doSomething<T>(value: NonStringIterable<T>): T;
148+
149+
const o = { foo() {} };
150+
151+
doSomething('value'); // error
152+
~~~~~~~
153+
!!! error TS2345: Argument of type '"value"' is not assignable to parameter of type 'never'.
154+
doSomething(['v']); // ok
155+
doSomething([o]); // ok
156+
doSomething([{ foo() {} }]); // ok
157+
158+
// https://github.com/microsoft/TypeScript/issues/55124
159+
type Values<T> = T[keyof T];
160+
type ExtractFields<Options> = Values<{
161+
[K in keyof Options]: Options[K] extends object ? keyof Options[K] : never;
162+
}>;
163+
type SetType<Options> = {
164+
[key: string]: any;
165+
target?: ExtractFields<Options>;
166+
};
167+
168+
declare function test55124<OptionsData extends SetType<OptionsData>>(
169+
options: OptionsData,
170+
): void;
171+
172+
test55124({
173+
target: "$test4", // ok
174+
data1: {
175+
$test1: 111,
176+
$test2: null,
177+
},
178+
data2: {
179+
$test3: {},
180+
$test4: () => {},
181+
$test5() {},
182+
},
183+
});
184+
185+
test55124({
186+
target: "$test6", // error
187+
~~~~~~
188+
!!! error TS2820: Type '"$test6"' is not assignable to type 'ExtractFields<{ target: "$test6"; data1: { $test1: number; $test2: null; }; data2: { $test3: {}; $test4: () => void; $test5(): void; }; }> | undefined'. Did you mean '"$test4"'?
189+
!!! related TS6500 thislessFunctionsNotContextSensitive1.ts:155:3: The expected type comes from property 'target' which is declared here on type 'SetType<{ target: "$test6"; data1: { $test1: number; $test2: null; }; data2: { $test3: {}; $test4: () => void; $test5(): void; }; }>'
190+
data1: {
191+
$test1: 111,
192+
$test2: null,
193+
},
194+
data2: {
195+
$test3: {},
196+
$test4: () => {},
197+
$test5() {},
198+
},
199+
});
200+
201+
// https://github.com/microsoft/TypeScript/issues/53924
202+
function test53924<T = unknown>(options: { a: (c: T) => void; b: () => T }) {}
203+
204+
test53924({
205+
a: (c) => {
206+
c; // number;
207+
},
208+
b: () => 123,
209+
});
210+
211+
test53924({
212+
b: () => 123,
213+
a: (c) => {
214+
return c; // number
215+
},
216+
});
217+
218+
test53924({
219+
b() {
220+
return 123;
221+
},
222+
a(c) {
223+
return c; // number
224+
},
225+
});
226+
227+
test53924({
228+
a(c) {
229+
return c; // number
230+
},
231+
b() {
232+
return 123;
233+
},
234+
});
235+
236+
// https://github.com/microsoft/TypeScript/issues/50258
237+
declare function monitor<T extends (...args: any) => any>(
238+
extractor: (...args: Parameters<T>) => Record<string, unknown>,
239+
executor: T,
240+
): (...args: Parameters<T>) => ReturnType<T>;
241+
242+
monitor(
243+
(p) => ({ p }), // { p: number }
244+
(p: number) => p,
245+
);
246+
monitor(
247+
(p) => ({ p }), // { p: number }
248+
function (p: number) {
249+
return p;
250+
},
251+
);
252+

0 commit comments

Comments
 (0)