Skip to content

Commit 379dce9

Browse files
committed
original checker and new tests/result
1 parent ca7a3af commit 379dce9

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @strict: true
2+
// @target: es6
3+
// @declaration: true
4+
5+
// #56013
6+
7+
// For reference, thise cases work as expected (no errors) when no external BooleanConstrudtor like overload is present
8+
declare const maybe: boolean;
9+
{
10+
const id = <T>() => (t: T) => !!t;
11+
12+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id());
13+
14+
result1;
15+
16+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
17+
18+
result2;
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @strict: true
2+
// @target: es6
3+
// @declaration: true
4+
5+
// #56013
6+
7+
const symbool = Symbol("MyBooleanSymbol");
8+
declare const MyBoolean: typeof Boolean & { prototype: typeof symbool };
9+
interface Array<T> {
10+
filter(predicate: typeof MyBoolean): (T extends (0 | 0n | "" | false | null | undefined) ? never : T)[];
11+
}
12+
13+
declare const maybe: boolean;
14+
{
15+
const id = <T>() => (t: T) => !!t;
16+
17+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(id()); // error before and after fix (so ignore type)
18+
// Errors before and after fix are different.
19+
// The error in the #56013 fixed case is:
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+
25+
26+
result1;
27+
28+
const result2 = ['foo', 'bar', undefined].filter(id()); // want id() = (t: string) => boolean
29+
30+
result2;
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @strict: true
2+
// @target: es6
3+
// @declaration: true
4+
5+
// #56013
6+
7+
const symbool = Symbol("MyBooleanSymbol");
8+
declare const MyBoolean: typeof Boolean & { prototype: typeof symbool };
9+
interface Array<T> {
10+
filter(predicate: typeof MyBoolean): (T extends (0 | 0n | "" | false | null | undefined) ? never : T)[];
11+
}
12+
13+
declare const maybe: boolean;
14+
{
15+
const id = <T,>() => (t: T) => !!t;
16+
17+
const result1 = (maybe ? ['foo', 'bar', undefined] : [1] ).filter(MyBoolean);
18+
19+
result1;
20+
21+
const result2 = ['foo', 'bar', undefined].filter(MyBoolean); // want id() = (t: string) => boolean
22+
23+
result2;
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @strict: true
2+
// @target: es6
3+
// @declaration: true
4+
5+
// #56013
6+
7+
interface F2<T extends number,U extends number> {
8+
(p1:(t:1)=>T,p2:(u:1)=>U):11;
9+
(p1:(t:1)=>T,p2:(u:U)=>U):19;
10+
(p1:(t:T)=>T,p2:(u:1)=>U):91;
11+
(p1:(t:T)=>T,p2:(u:U)=>U):99;
12+
}
13+
type ID = <I>() => (i:I) => I;
14+
15+
declare const id: ID;
16+
17+
18+
const t11 = (0 as any as F2<1,1>)(id(),id());
19+
const t12 = (0 as any as F2<1,2>)(id(),id());
20+
const t21 = (0 as any as F2<2,1>)(id(),id());
21+
const t22 = (0 as any as F2<2,2>)(id(),id());
22+
23+
t11 satisfies 11;
24+
t12 satisfies 19;
25+
t21 satisfies 91;
26+
t22 satisfies 99;
27+

0 commit comments

Comments
 (0)