|
| 1 | +tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts(67,42): error TS2339: Property 'toString' does not exist on type 'T'. |
| 2 | + |
| 3 | + |
| 4 | +==== tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts (1 errors) ==== |
| 5 | + // This test case is a condensed version of Angular 2's ListWrapper. Prior to #7448 |
| 6 | + // this would cause the compiler to run out of memory. |
| 7 | + |
| 8 | + function outer<T>(x: T) { |
| 9 | + class Inner { |
| 10 | + static y: T = x; |
| 11 | + } |
| 12 | + return Inner; |
| 13 | + } |
| 14 | + let y: number = outer(5).y; |
| 15 | + |
| 16 | + class ListWrapper2 { |
| 17 | + static clone<T>(dit: typeof ListWrapper2, array: T[]): T[] { return array.slice(0); } |
| 18 | + static reversed<T>(dit: typeof ListWrapper2, array: T[]): T[] { |
| 19 | + var a = ListWrapper2.clone(dit, array); |
| 20 | + return a; |
| 21 | + } |
| 22 | + } |
| 23 | + namespace tessst { |
| 24 | + /** |
| 25 | + * Iterates through 'array' by index and performs the callback on each element of array until the callback |
| 26 | + * returns a truthy value, then returns that value. |
| 27 | + * If no such value is found, the callback is applied to each element of array and undefined is returned. |
| 28 | + */ |
| 29 | + export function funkyFor<T, U>(array: T[], callback: (element: T, index: number) => U): U { |
| 30 | + if (array) { |
| 31 | + for (let i = 0, len = array.length; i < len; i++) { |
| 32 | + const result = callback(array[i], i); |
| 33 | + if (result) { |
| 34 | + return result; |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + return undefined; |
| 39 | + } |
| 40 | + } |
| 41 | + interface Scanner { |
| 42 | + scanRange<T>(start: number, length: number, callback: () => T): T; |
| 43 | + } |
| 44 | + class ListWrapper { |
| 45 | + // JS has no way to express a statically fixed size list, but dart does so we |
| 46 | + // keep both methods. |
| 47 | + static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } |
| 48 | + static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } |
| 49 | + static clone<T>(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } |
| 50 | + static forEachWithIndex<T>(dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) { |
| 51 | + for (var i = 0; i < array.length; i++) { |
| 52 | + fn(array[i], i); |
| 53 | + } |
| 54 | + } |
| 55 | + static first<T>(dit: typeof ListWrapper, array: T[]): T { |
| 56 | + if (!array) return null; |
| 57 | + return array[0]; |
| 58 | + } |
| 59 | + static last<T>(dit: typeof ListWrapper, array: T[]): T { |
| 60 | + if (!array || array.length == 0) return null; |
| 61 | + return array[array.length - 1]; |
| 62 | + } |
| 63 | + static indexOf<T>(dit: typeof ListWrapper, array: T[], value: T, startIndex: number = 0): number { |
| 64 | + return array.indexOf(value, startIndex); |
| 65 | + } |
| 66 | + static contains<T>(dit: typeof ListWrapper, list: T[], el: T): boolean { return list.indexOf(el) !== -1; } |
| 67 | + static reversed<T>(dit: typeof ListWrapper, array: T[]): T[] { |
| 68 | + var a = ListWrapper.clone(dit, array); |
| 69 | + let scanner: Scanner; |
| 70 | + scanner.scanRange(3, 5, () => { }); |
| 71 | + return tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a; |
| 72 | + ~~~~~~~~ |
| 73 | +!!! error TS2339: Property 'toString' does not exist on type 'T'. |
| 74 | + } |
| 75 | + static concat(dit: typeof ListWrapper, a: any[], b: any[]): any[] { return a.concat(b); } |
| 76 | + static insert<T>(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); } |
| 77 | + static removeAt<T>(dit: typeof ListWrapper, list: T[], index: number): T { |
| 78 | + var res = list[index]; |
| 79 | + list.splice(index, 1); |
| 80 | + return res; |
| 81 | + } |
| 82 | + static removeAll<T>(dit: typeof ListWrapper, list: T[], items: T[]) { |
| 83 | + for (var i = 0; i < items.length; ++i) { |
| 84 | + var index = list.indexOf(items[i]); |
| 85 | + list.splice(index, 1); |
| 86 | + } |
| 87 | + } |
| 88 | + static remove<T>(dit: typeof ListWrapper, list: T[], el: T): boolean { |
| 89 | + var index = list.indexOf(el); |
| 90 | + if (index > -1) { |
| 91 | + list.splice(index, 1); |
| 92 | + return true; |
| 93 | + } |
| 94 | + return false; |
| 95 | + } |
| 96 | + static clear(dit: typeof ListWrapper, list: any[]) { list.length = 0; } |
| 97 | + static isEmpty(dit: typeof ListWrapper, list: any[]): boolean { return list.length == 0; } |
| 98 | + static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { |
| 99 | + list.fill(value, start, end === null ? list.length : end); |
| 100 | + } |
| 101 | + static equals(dit: typeof ListWrapper, a: any[], b: any[]): boolean { |
| 102 | + if (a.length != b.length) return false; |
| 103 | + for (var i = 0; i < a.length; ++i) { |
| 104 | + if (a[i] !== b[i]) return false; |
| 105 | + } |
| 106 | + return true; |
| 107 | + } |
| 108 | + static slice<T>(dit: typeof ListWrapper, l: T[], from: number = 0, to: number = null): T[] { |
| 109 | + return l.slice(from, to === null ? undefined : to); |
| 110 | + } |
| 111 | + static splice<T>(dit: typeof ListWrapper, l: T[], from: number, length: number): T[] { return l.splice(from, length); } |
| 112 | + static sort<T>(dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) { |
| 113 | + if (isPresent(compareFn)) { |
| 114 | + l.sort(compareFn); |
| 115 | + } else { |
| 116 | + l.sort(); |
| 117 | + } |
| 118 | + } |
| 119 | + static toString<T>(dit: typeof ListWrapper, l: T[]): string { return l.toString(); } |
| 120 | + static toJSON<T>(dit: typeof ListWrapper, l: T[]): string { return JSON.stringify(l); } |
| 121 | + |
| 122 | + static maximum<T>(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { |
| 123 | + if (list.length == 0) { |
| 124 | + return null; |
| 125 | + } |
| 126 | + var solution: T = null; |
| 127 | + var maxValue = -Infinity; |
| 128 | + for (var index = 0; index < list.length; index++) { |
| 129 | + var candidate = list[index]; |
| 130 | + if (isBlank(candidate)) { |
| 131 | + continue; |
| 132 | + } |
| 133 | + var candidateValue = predicate(candidate); |
| 134 | + if (candidateValue > maxValue) { |
| 135 | + solution = candidate; |
| 136 | + maxValue = candidateValue; |
| 137 | + } |
| 138 | + } |
| 139 | + return solution; |
| 140 | + } |
| 141 | + } |
| 142 | + let cloned = ListWrapper.clone(ListWrapper, [1,2,3,4]); |
| 143 | + declare function isBlank(x: any): boolean; |
| 144 | + declare function isPresent<T>(compareFn?: (a: T, b: T) => number): boolean; |
| 145 | + interface Array<T> { |
| 146 | + fill(value: any, start: number, end: number): void; |
| 147 | + } |
0 commit comments