|
| 1 | +three.ts(28,14): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? |
| 2 | + |
| 3 | + |
| 4 | +==== one.ts (0 errors) ==== |
| 5 | + declare const y: never[] | string[]; |
| 6 | + export const yThen = y.map(item => item.length); |
| 7 | +==== two.ts (0 errors) ==== |
| 8 | + declare const y: number[][] | string[]; |
| 9 | + export const yThen = y.map(item => item.length); |
| 10 | +==== three.ts (1 errors) ==== |
| 11 | + // #42504 |
| 12 | + interface ResizeObserverCallback { |
| 13 | + (entries: ResizeObserverEntry[], observer: ResizeObserver): void; |
| 14 | + } |
| 15 | + interface ResizeObserverCallback { // duplicate for effect |
| 16 | + (entries: ResizeObserverEntry[], observer: ResizeObserver): void; |
| 17 | + } |
| 18 | + |
| 19 | + const resizeObserver = new ResizeObserver(([entry]) => { |
| 20 | + entry |
| 21 | + }); |
| 22 | + // comment in #35501 |
| 23 | + interface Callback<T> { |
| 24 | + (error: null, result: T): unknown |
| 25 | + (error: Error, result: null): unknown |
| 26 | + } |
| 27 | + |
| 28 | + interface Task<T> { |
| 29 | + (callback: Callback<T>): unknown |
| 30 | + } |
| 31 | + |
| 32 | + export function series<T>(tasks: Task<T>[], callback: Callback<T[]>): void { |
| 33 | + let index = 0 |
| 34 | + let results: T[] = [] |
| 35 | + |
| 36 | + function next() { |
| 37 | + let task = tasks[index] |
| 38 | + if (!task) { |
| 39 | + ~~~~ |
| 40 | +!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? |
| 41 | + callback(null, results) |
| 42 | + } else { |
| 43 | + task((error, result) => { |
| 44 | + if (error) { |
| 45 | + callback(error, null) |
| 46 | + } else { |
| 47 | + // must use postfix-!, since `error` and `result` don't have a |
| 48 | + // causal relationship when the overloads are combined |
| 49 | + results.push(result!) |
| 50 | + next() |
| 51 | + } |
| 52 | + }) |
| 53 | + } |
| 54 | + } |
| 55 | + next() |
| 56 | + } |
| 57 | + |
| 58 | + series([ |
| 59 | + cb => setTimeout(() => cb(null, 1), 300), |
| 60 | + cb => setTimeout(() => cb(null, 2), 200), |
| 61 | + cb => setTimeout(() => cb(null, 3), 100), |
| 62 | + ], (error, results) => { |
| 63 | + if (error) { |
| 64 | + console.error(error) |
| 65 | + } else { |
| 66 | + console.log(results) |
| 67 | + } |
| 68 | + }) |
| 69 | + |
0 commit comments