Skip to content

Commit 4b8b0a5

Browse files
committed
Some tests from some design limitation issues this fixes
1 parent 83987a7 commit 4b8b0a5

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [overloadedGenericInference.ts]
2+
// #35501
3+
declare function fn(x: string): string;
4+
declare function fn(x: string[]): string;
5+
6+
declare function map<A, R>(fn: (item: A) => R, list: A[]): R[];
7+
8+
const mapped = map(fn, ['1']);
9+
10+
// #30294 (partial fix)
11+
declare class C {
12+
static x(y: number): number;
13+
static x(): number;
14+
}
15+
C.x.call(C, 1); // ok
16+
C.x.call(C); // ok
17+
C.x.call(1); // ok (not an error because the `this` type of `x` is not constrained)
18+
19+
20+
//// [overloadedGenericInference.js]
21+
"use strict";
22+
const mapped = map(fn, ['1']);
23+
C.x.call(C, 1); // ok
24+
C.x.call(C); // ok
25+
C.x.call(1); // ok (not an error because the `this` type of `x` is not constrained)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
=== tests/cases/compiler/overloadedGenericInference.ts ===
2+
// #35501
3+
declare function fn(x: string): string;
4+
>fn : Symbol(fn, Decl(overloadedGenericInference.ts, 0, 0), Decl(overloadedGenericInference.ts, 1, 39))
5+
>x : Symbol(x, Decl(overloadedGenericInference.ts, 1, 20))
6+
7+
declare function fn(x: string[]): string;
8+
>fn : Symbol(fn, Decl(overloadedGenericInference.ts, 0, 0), Decl(overloadedGenericInference.ts, 1, 39))
9+
>x : Symbol(x, Decl(overloadedGenericInference.ts, 2, 20))
10+
11+
declare function map<A, R>(fn: (item: A) => R, list: A[]): R[];
12+
>map : Symbol(map, Decl(overloadedGenericInference.ts, 2, 41))
13+
>A : Symbol(A, Decl(overloadedGenericInference.ts, 4, 21))
14+
>R : Symbol(R, Decl(overloadedGenericInference.ts, 4, 23))
15+
>fn : Symbol(fn, Decl(overloadedGenericInference.ts, 4, 27))
16+
>item : Symbol(item, Decl(overloadedGenericInference.ts, 4, 32))
17+
>A : Symbol(A, Decl(overloadedGenericInference.ts, 4, 21))
18+
>R : Symbol(R, Decl(overloadedGenericInference.ts, 4, 23))
19+
>list : Symbol(list, Decl(overloadedGenericInference.ts, 4, 46))
20+
>A : Symbol(A, Decl(overloadedGenericInference.ts, 4, 21))
21+
>R : Symbol(R, Decl(overloadedGenericInference.ts, 4, 23))
22+
23+
const mapped = map(fn, ['1']);
24+
>mapped : Symbol(mapped, Decl(overloadedGenericInference.ts, 6, 5))
25+
>map : Symbol(map, Decl(overloadedGenericInference.ts, 2, 41))
26+
>fn : Symbol(fn, Decl(overloadedGenericInference.ts, 0, 0), Decl(overloadedGenericInference.ts, 1, 39))
27+
28+
// #30294 (partial fix)
29+
declare class C {
30+
>C : Symbol(C, Decl(overloadedGenericInference.ts, 6, 30))
31+
32+
static x(y: number): number;
33+
>x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
34+
>y : Symbol(y, Decl(overloadedGenericInference.ts, 10, 13))
35+
36+
static x(): number;
37+
>x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
38+
}
39+
C.x.call(C, 1); // ok
40+
>C.x.call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --))
41+
>C.x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
42+
>C : Symbol(C, Decl(overloadedGenericInference.ts, 6, 30))
43+
>x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
44+
>call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --))
45+
>C : Symbol(C, Decl(overloadedGenericInference.ts, 6, 30))
46+
47+
C.x.call(C); // ok
48+
>C.x.call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --))
49+
>C.x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
50+
>C : Symbol(C, Decl(overloadedGenericInference.ts, 6, 30))
51+
>x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
52+
>call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --))
53+
>C : Symbol(C, Decl(overloadedGenericInference.ts, 6, 30))
54+
55+
C.x.call(1); // ok (not an error because the `this` type of `x` is not constrained)
56+
>C.x.call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --))
57+
>C.x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
58+
>C : Symbol(C, Decl(overloadedGenericInference.ts, 6, 30))
59+
>x : Symbol(C.x, Decl(overloadedGenericInference.ts, 9, 17), Decl(overloadedGenericInference.ts, 10, 32))
60+
>call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --))
61+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
=== tests/cases/compiler/overloadedGenericInference.ts ===
2+
// #35501
3+
declare function fn(x: string): string;
4+
>fn : { (x: string): string; (x: string[]): string; }
5+
>x : string
6+
7+
declare function fn(x: string[]): string;
8+
>fn : { (x: string): string; (x: string[]): string; }
9+
>x : string[]
10+
11+
declare function map<A, R>(fn: (item: A) => R, list: A[]): R[];
12+
>map : <A, R>(fn: (item: A) => R, list: A[]) => R[]
13+
>fn : (item: A) => R
14+
>item : A
15+
>list : A[]
16+
17+
const mapped = map(fn, ['1']);
18+
>mapped : string[]
19+
>map(fn, ['1']) : string[]
20+
>map : <A, R>(fn: (item: A) => R, list: A[]) => R[]
21+
>fn : { (x: string): string; (x: string[]): string; }
22+
>['1'] : string[]
23+
>'1' : "1"
24+
25+
// #30294 (partial fix)
26+
declare class C {
27+
>C : C
28+
29+
static x(y: number): number;
30+
>x : { (y: number): number; (): number; }
31+
>y : number
32+
33+
static x(): number;
34+
>x : { (y: number): number; (): number; }
35+
}
36+
C.x.call(C, 1); // ok
37+
>C.x.call(C, 1) : number
38+
>C.x.call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R
39+
>C.x : { (y: number): number; (): number; }
40+
>C : typeof C
41+
>x : { (y: number): number; (): number; }
42+
>call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R
43+
>C : typeof C
44+
>1 : 1
45+
46+
C.x.call(C); // ok
47+
>C.x.call(C) : number
48+
>C.x.call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R
49+
>C.x : { (y: number): number; (): number; }
50+
>C : typeof C
51+
>x : { (y: number): number; (): number; }
52+
>call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R
53+
>C : typeof C
54+
55+
C.x.call(1); // ok (not an error because the `this` type of `x` is not constrained)
56+
>C.x.call(1) : number
57+
>C.x.call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R
58+
>C.x : { (y: number): number; (): number; }
59+
>C : typeof C
60+
>x : { (y: number): number; (): number; }
61+
>call : <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R
62+
>1 : 1
63+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @target: es6
2+
// @strict: true
3+
// #35501
4+
declare function fn(x: string): string;
5+
declare function fn(x: string[]): string;
6+
7+
declare function map<A, R>(fn: (item: A) => R, list: A[]): R[];
8+
9+
const mapped = map(fn, ['1']);
10+
11+
// #30294 (partial fix)
12+
declare class C {
13+
static x(y: number): number;
14+
static x(): number;
15+
}
16+
C.x.call(C, 1); // ok
17+
C.x.call(C); // ok
18+
C.x.call(1); // ok (not an error because the `this` type of `x` is not constrained)

0 commit comments

Comments
 (0)