|
| 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