Skip to content

Commit d1cfec5

Browse files
committed
original checker and new tests/result
original source and new tests/results
1 parent ca7a3af commit d1cfec5

18 files changed

+961
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/arrayFilterBooleanExternalOverload1.ts] ////
2+
3+
//// [arrayFilterBooleanExternalOverload1.ts]
4+
// #56013
5+
6+
// For reference, thise cases work as expected (no errors) when no external BooleanConstrudtor like overload is present
7+
declare const maybe: boolean;
8+
{
9+
const id = <T>() => (t: T) => !!t;
10+
11+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id());
12+
13+
result1;
14+
15+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
16+
17+
result2;
18+
}
19+
20+
21+
//// [arrayFilterBooleanExternalOverload1.js]
22+
"use strict";
23+
// #56013
24+
{
25+
const id = () => (t) => !!t;
26+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1]).filter(id());
27+
result1;
28+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
29+
result2;
30+
}
31+
32+
33+
//// [arrayFilterBooleanExternalOverload1.d.ts]
34+
declare const maybe: boolean;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/arrayFilterBooleanExternalOverload1.ts] ////
2+
3+
=== arrayFilterBooleanExternalOverload1.ts ===
4+
// #56013
5+
6+
// For reference, thise cases work as expected (no errors) when no external BooleanConstrudtor like overload is present
7+
declare const maybe: boolean;
8+
>maybe : Symbol(maybe, Decl(arrayFilterBooleanExternalOverload1.ts, 3, 13))
9+
{
10+
const id = <T>() => (t: T) => !!t;
11+
>id : Symbol(id, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 9))
12+
>T : Symbol(T, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 16))
13+
>t : Symbol(t, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 25))
14+
>T : Symbol(T, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 16))
15+
>t : Symbol(t, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 25))
16+
17+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id());
18+
>result1 : Symbol(result1, Decl(arrayFilterBooleanExternalOverload1.ts, 7, 9))
19+
>(maybe ? ['foo', 'bar', undefined] : [1] ).filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
20+
>maybe : Symbol(maybe, Decl(arrayFilterBooleanExternalOverload1.ts, 3, 13))
21+
>undefined : Symbol(undefined)
22+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
23+
>id : Symbol(id, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 9))
24+
25+
result1;
26+
>result1 : Symbol(result1, Decl(arrayFilterBooleanExternalOverload1.ts, 7, 9))
27+
28+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
29+
>result2 : Symbol(result2, Decl(arrayFilterBooleanExternalOverload1.ts, 11, 9))
30+
>['foo', 'bar', undefined].filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
31+
>undefined : Symbol(undefined)
32+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
33+
>id : Symbol(id, Decl(arrayFilterBooleanExternalOverload1.ts, 5, 9))
34+
35+
result2;
36+
>result2 : Symbol(result2, Decl(arrayFilterBooleanExternalOverload1.ts, 11, 9))
37+
}
38+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//// [tests/cases/compiler/arrayFilterBooleanExternalOverload1.ts] ////
2+
3+
=== arrayFilterBooleanExternalOverload1.ts ===
4+
// #56013
5+
6+
// For reference, thise cases work as expected (no errors) when no external BooleanConstrudtor like overload is present
7+
declare const maybe: boolean;
8+
>maybe : boolean
9+
{
10+
const id = <T>() => (t: T) => !!t;
11+
>id : <T>() => (t: T) => boolean
12+
><T>() => (t: T) => !!t : <T>() => (t: T) => boolean
13+
>(t: T) => !!t : (t: T) => boolean
14+
>t : T
15+
>!!t : boolean
16+
>!t : boolean
17+
>t : T
18+
19+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id());
20+
>result1 : (string | number | undefined)[]
21+
>(maybe ? ['foo', 'bar', undefined] : [1] ).filter(id()) : (string | number | undefined)[]
22+
>(maybe ? ['foo', 'bar', undefined] : [1] ).filter : { <S extends string | undefined>(predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => value is S, thisArg?: any): S[]; (predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => unknown, thisArg?: any): (string | undefined)[]; } | { <S_1 extends number>(predicate: (value: number, index: number, array: number[]) => value is S_1, thisArg?: any): S_1[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): number[]; }
23+
>(maybe ? ['foo', 'bar', undefined] : [1] ) : (string | undefined)[] | number[]
24+
>maybe ? ['foo', 'bar', undefined] : [1] : (string | undefined)[] | number[]
25+
>maybe : boolean
26+
>['foo', 'bar', undefined] : (string | undefined)[]
27+
>'foo' : "foo"
28+
>'bar' : "bar"
29+
>undefined : undefined
30+
>[1] : number[]
31+
>1 : 1
32+
>filter : { <S extends string | undefined>(predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => value is S, thisArg?: any): S[]; (predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => unknown, thisArg?: any): (string | undefined)[]; } | { <S_1 extends number>(predicate: (value: number, index: number, array: number[]) => value is S_1, thisArg?: any): S_1[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): number[]; }
33+
>id() : (t: string | number | undefined) => boolean
34+
>id : <T>() => (t: T) => boolean
35+
36+
result1;
37+
>result1 : (string | number | undefined)[]
38+
39+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
40+
>result2 : (string | undefined)[]
41+
>['foo', 'bar', undefined].filter(id()) : (string | undefined)[]
42+
>['foo', 'bar', undefined].filter : { <S extends string | undefined>(predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => value is S, thisArg?: any): S[]; (predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => unknown, thisArg?: any): (string | undefined)[]; }
43+
>['foo', 'bar', undefined] : (string | undefined)[]
44+
>'foo' : "foo"
45+
>'bar' : "bar"
46+
>undefined : undefined
47+
>filter : { <S extends string | undefined>(predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => value is S, thisArg?: any): S[]; (predicate: (value: string | undefined, index: number, array: (string | undefined)[]) => unknown, thisArg?: any): (string | undefined)[]; }
48+
>id() : (t: string | undefined) => boolean
49+
>id : <T>() => (t: T) => boolean
50+
51+
result2;
52+
>result2 : (string | undefined)[]
53+
}
54+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
arrayFilterBooleanExternalOverload2.ts(13,71): error TS2345: Argument of type '(t: unknown) => boolean' is not assignable to parameter of type 'BooleanConstructor & { prototype: unique symbol; }'.
2+
Type '(t: unknown) => boolean' is not assignable to type 'BooleanConstructor'.
3+
Type '(t: unknown) => boolean' provides no match for the signature 'new (value?: any): Boolean'.
4+
5+
6+
==== arrayFilterBooleanExternalOverload2.ts (1 errors) ====
7+
// #56013
8+
9+
const symbool = Symbol("MyBooleanSymbol");
10+
declare const MyBoolean: typeof Boolean & { prototype: typeof symbool };
11+
interface Array<T> {
12+
filter(predicate: typeof MyBoolean): (T extends (0 | 0n | "" | false | null | undefined) ? never : T)[];
13+
}
14+
15+
declare const maybe: boolean;
16+
{
17+
const id = <T>() => (t: T) => !!t;
18+
19+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id()); // error before and after fix (so ignore type)
20+
~~~~
21+
!!! error TS2345: Argument of type '(t: unknown) => boolean' is not assignable to parameter of type 'BooleanConstructor & { prototype: unique symbol; }'.
22+
!!! error TS2345: Type '(t: unknown) => boolean' is not assignable to type 'BooleanConstructor'.
23+
!!! error TS2345: Type '(t: unknown) => boolean' provides no match for the signature 'new (value?: any): Boolean'.
24+
// Errors before and after fix are different.
25+
// The error in the #56013 fixed case is:
26+
// ~~~~
27+
// error TS2345: Argument of type '(t: unknown) => boolean' is not assignable to parameter of type 'BooleanConstructor & { prototype: unique symbol; }'.
28+
// error TS2345: Type '(t: unknown) => boolean' is not assignable to type 'BooleanConstructor'.
29+
// error TS2345: Type '(t: unknown) => boolean' provides no match for the signature 'new (value?: any): Boolean'.
30+
31+
32+
result1;
33+
34+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
35+
36+
result2;
37+
}
38+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//// [tests/cases/compiler/arrayFilterBooleanExternalOverload2.ts] ////
2+
3+
//// [arrayFilterBooleanExternalOverload2.ts]
4+
// #56013
5+
6+
const symbool = Symbol("MyBooleanSymbol");
7+
declare const MyBoolean: typeof Boolean & { prototype: typeof symbool };
8+
interface Array<T> {
9+
filter(predicate: typeof MyBoolean): (T extends (0 | 0n | "" | false | null | undefined) ? never : T)[];
10+
}
11+
12+
declare const maybe: boolean;
13+
{
14+
const id = <T>() => (t: T) => !!t;
15+
16+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id()); // error before and after fix (so ignore type)
17+
// Errors before and after fix are different.
18+
// The error in the #56013 fixed case is:
19+
// ~~~~
20+
// error TS2345: Argument of type '(t: unknown) => boolean' is not assignable to parameter of type 'BooleanConstructor & { prototype: unique symbol; }'.
21+
// error TS2345: Type '(t: unknown) => boolean' is not assignable to type 'BooleanConstructor'.
22+
// error TS2345: Type '(t: unknown) => boolean' provides no match for the signature 'new (value?: any): Boolean'.
23+
24+
25+
result1;
26+
27+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
28+
29+
result2;
30+
}
31+
32+
33+
//// [arrayFilterBooleanExternalOverload2.js]
34+
"use strict";
35+
// #56013
36+
const symbool = Symbol("MyBooleanSymbol");
37+
{
38+
const id = () => (t) => !!t;
39+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1]).filter(id()); // error before and after fix (so ignore type)
40+
// Errors before and after fix are different.
41+
// The error in the #56013 fixed case is:
42+
// ~~~~
43+
// error TS2345: Argument of type '(t: unknown) => boolean' is not assignable to parameter of type 'BooleanConstructor & { prototype: unique symbol; }'.
44+
// error TS2345: Type '(t: unknown) => boolean' is not assignable to type 'BooleanConstructor'.
45+
// error TS2345: Type '(t: unknown) => boolean' provides no match for the signature 'new (value?: any): Boolean'.
46+
result1;
47+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
48+
result2;
49+
}
50+
51+
52+
//// [arrayFilterBooleanExternalOverload2.d.ts]
53+
declare const symbool: unique symbol;
54+
declare const MyBoolean: typeof Boolean & {
55+
prototype: typeof symbool;
56+
};
57+
interface Array<T> {
58+
filter(predicate: typeof MyBoolean): (T extends (0 | 0n | "" | false | null | undefined) ? never : T)[];
59+
}
60+
declare const maybe: boolean;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//// [tests/cases/compiler/arrayFilterBooleanExternalOverload2.ts] ////
2+
3+
=== arrayFilterBooleanExternalOverload2.ts ===
4+
// #56013
5+
6+
const symbool = Symbol("MyBooleanSymbol");
7+
>symbool : Symbol(symbool, Decl(arrayFilterBooleanExternalOverload2.ts, 2, 5))
8+
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
9+
10+
declare const MyBoolean: typeof Boolean & { prototype: typeof symbool };
11+
>MyBoolean : Symbol(MyBoolean, Decl(arrayFilterBooleanExternalOverload2.ts, 3, 13))
12+
>Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
13+
>prototype : Symbol(prototype, Decl(arrayFilterBooleanExternalOverload2.ts, 3, 43))
14+
>symbool : Symbol(symbool, Decl(arrayFilterBooleanExternalOverload2.ts, 2, 5))
15+
16+
interface Array<T> {
17+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 1 more)
18+
>T : Symbol(T, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 16))
19+
20+
filter(predicate: typeof MyBoolean): (T extends (0 | 0n | "" | false | null | undefined) ? never : T)[];
21+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 20))
22+
>predicate : Symbol(predicate, Decl(arrayFilterBooleanExternalOverload2.ts, 5, 11))
23+
>MyBoolean : Symbol(MyBoolean, Decl(arrayFilterBooleanExternalOverload2.ts, 3, 13))
24+
>T : Symbol(T, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 16))
25+
>T : Symbol(T, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 16))
26+
}
27+
28+
declare const maybe: boolean;
29+
>maybe : Symbol(maybe, Decl(arrayFilterBooleanExternalOverload2.ts, 8, 13))
30+
{
31+
const id = <T>() => (t: T) => !!t;
32+
>id : Symbol(id, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 9))
33+
>T : Symbol(T, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 16))
34+
>t : Symbol(t, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 25))
35+
>T : Symbol(T, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 16))
36+
>t : Symbol(t, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 25))
37+
38+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id()); // error before and after fix (so ignore type)
39+
>result1 : Symbol(result1, Decl(arrayFilterBooleanExternalOverload2.ts, 12, 9))
40+
>(maybe ? ['foo', 'bar', undefined] : [1] ).filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 20), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 1 more)
41+
>maybe : Symbol(maybe, Decl(arrayFilterBooleanExternalOverload2.ts, 8, 13))
42+
>undefined : Symbol(undefined)
43+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 20), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 1 more)
44+
>id : Symbol(id, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 9))
45+
46+
// Errors before and after fix are different.
47+
// The error in the #56013 fixed case is:
48+
// ~~~~
49+
// error TS2345: Argument of type '(t: unknown) => boolean' is not assignable to parameter of type 'BooleanConstructor & { prototype: unique symbol; }'.
50+
// error TS2345: Type '(t: unknown) => boolean' is not assignable to type 'BooleanConstructor'.
51+
// error TS2345: Type '(t: unknown) => boolean' provides no match for the signature 'new (value?: any): Boolean'.
52+
53+
54+
result1;
55+
>result1 : Symbol(result1, Decl(arrayFilterBooleanExternalOverload2.ts, 12, 9))
56+
57+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
58+
>result2 : Symbol(result2, Decl(arrayFilterBooleanExternalOverload2.ts, 23, 9))
59+
>['foo', 'bar', undefined].filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 20))
60+
>undefined : Symbol(undefined)
61+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(arrayFilterBooleanExternalOverload2.ts, 4, 20))
62+
>id : Symbol(id, Decl(arrayFilterBooleanExternalOverload2.ts, 10, 9))
63+
64+
result2;
65+
>result2 : Symbol(result2, Decl(arrayFilterBooleanExternalOverload2.ts, 23, 9))
66+
}
67+

0 commit comments

Comments
 (0)