|
| 1 | +tests/cases/compiler/unionOfClassCalls.ts(28,5): error TS2349: This expression is not callable. |
| 2 | + Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }' has signatures, but none of those signatures are compatible with each other. |
| 3 | + |
| 4 | + |
| 5 | +==== tests/cases/compiler/unionOfClassCalls.ts (1 errors) ==== |
| 6 | + // from https://github.com/microsoft/TypeScript/issues/30717 |
| 7 | + declare class Test<T> { |
| 8 | + obj: T; |
| 9 | + get<K extends keyof T>(k: K): T[K]; |
| 10 | + } |
| 11 | + |
| 12 | + interface A { t: "A" } |
| 13 | + interface B { t: "B" } |
| 14 | + |
| 15 | + declare const tmp: Test<A> | Test<B>; |
| 16 | + |
| 17 | + switch (tmp.get('t')) { |
| 18 | + case 'A': break; |
| 19 | + case 'B': break; |
| 20 | + } |
| 21 | + |
| 22 | + // from https://github.com/microsoft/TypeScript/issues/36390 |
| 23 | + |
| 24 | + const arr: number[] | string[] = []; // Works with Array<number | string> |
| 25 | + const arr1: number[] = []; |
| 26 | + const arr2: string[] = []; |
| 27 | + |
| 28 | + arr.map((a: number | string, index: number) => { |
| 29 | + return index |
| 30 | + }) |
| 31 | + |
| 32 | + // This case still doesn't work because `reduce` has multiple overloads :( |
| 33 | + arr.reduce((acc: Array<string>, a: number | string, index: number) => { |
| 34 | + ~~~~~~ |
| 35 | +!!! error TS2349: This expression is not callable. |
| 36 | +!!! error TS2349: Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }' has signatures, but none of those signatures are compatible with each other. |
| 37 | + return [] |
| 38 | + }, []) |
| 39 | + |
| 40 | + arr.forEach((a: number | string, index: number) => { |
| 41 | + return index |
| 42 | + }) |
| 43 | + |
| 44 | + arr1.map((a: number, index: number) => { |
| 45 | + return index |
| 46 | + }) |
| 47 | + |
| 48 | + arr1.reduce((acc: number[], a: number, index: number) => { |
| 49 | + return [a] |
| 50 | + }, []) |
| 51 | + |
| 52 | + arr1.forEach((a: number, index: number) => { |
| 53 | + return index |
| 54 | + }) |
| 55 | + arr2.map((a: string, index: number) => { |
| 56 | + return index |
| 57 | + }) |
| 58 | + |
| 59 | + arr2.reduce((acc: string[], a: string, index: number) => { |
| 60 | + return [] |
| 61 | + }, []) |
| 62 | + |
| 63 | + arr2.forEach((a: string, index: number) => { |
| 64 | + return index |
| 65 | + }) |
| 66 | + |
| 67 | + // from https://github.com/microsoft/TypeScript/issues/36307 |
| 68 | + |
| 69 | + declare class Foo { |
| 70 | + doThing(): Promise<this> |
| 71 | + } |
| 72 | + |
| 73 | + declare class Bar extends Foo { |
| 74 | + bar: number; |
| 75 | + } |
| 76 | + declare class Baz extends Foo { |
| 77 | + baz: number; |
| 78 | + } |
| 79 | + |
| 80 | + declare var a: Bar | Baz; |
| 81 | + // note, you must annotate `result` for now |
| 82 | + a.doThing().then((result: Bar | Baz) => { |
| 83 | + // whatever |
| 84 | + }); |
| 85 | + |
0 commit comments