|
| 1 | +unconstrainedTypeComparison.ts(2,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 2 | +unconstrainedTypeComparison.ts(2,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 3 | +unconstrainedTypeComparison.ts(6,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 4 | +unconstrainedTypeComparison.ts(6,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 5 | +unconstrainedTypeComparison.ts(10,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 6 | +unconstrainedTypeComparison.ts(10,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 7 | +unconstrainedTypeComparison.ts(14,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 8 | +unconstrainedTypeComparison.ts(14,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 9 | +unconstrainedTypeComparison.ts(18,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 10 | +unconstrainedTypeComparison.ts(18,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 11 | +unconstrainedTypeComparison.ts(22,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 12 | +unconstrainedTypeComparison.ts(22,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 13 | +unconstrainedTypeComparison.ts(26,12): error TS18048: 'a' is possibly 'undefined'. |
| 14 | +unconstrainedTypeComparison.ts(26,16): error TS18048: 'b' is possibly 'undefined'. |
| 15 | +unconstrainedTypeComparison.ts(30,12): error TS18047: 'a' is possibly 'null'. |
| 16 | +unconstrainedTypeComparison.ts(30,16): error TS18047: 'b' is possibly 'null'. |
| 17 | +unconstrainedTypeComparison.ts(34,12): error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 18 | +unconstrainedTypeComparison.ts(34,16): error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 19 | +unconstrainedTypeComparison.ts(38,12): error TS18049: 'x' is possibly 'null' or 'undefined'. |
| 20 | +unconstrainedTypeComparison.ts(38,16): error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 21 | +unconstrainedTypeComparison.ts(42,12): error TS18049: 'x' is possibly 'null' or 'undefined'. |
| 22 | +unconstrainedTypeComparison.ts(42,16): error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 23 | +unconstrainedTypeComparison.ts(49,12): error TS18047: 'x' is possibly 'null'. |
| 24 | +unconstrainedTypeComparison.ts(49,16): error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 25 | +unconstrainedTypeComparison.ts(56,12): error TS18047: 'x' is possibly 'null'. |
| 26 | +unconstrainedTypeComparison.ts(56,16): error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 27 | +unconstrainedTypeComparison.ts(60,12): error TS18049: 'x' is possibly 'null' or 'undefined'. |
| 28 | +unconstrainedTypeComparison.ts(60,16): error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 29 | +unconstrainedTypeComparison.ts(74,12): error TS18047: 'x' is possibly 'null'. |
| 30 | +unconstrainedTypeComparison.ts(74,16): error TS18048: 'y' is possibly 'undefined'. |
| 31 | +unconstrainedTypeComparison.ts(85,12): error TS18047: 'a' is possibly 'null'. |
| 32 | +unconstrainedTypeComparison.ts(85,16): error TS18048: 'b' is possibly 'undefined'. |
| 33 | + |
| 34 | + |
| 35 | +==== unconstrainedTypeComparison.ts (32 errors) ==== |
| 36 | + function f1<T>(a: T, b: T): boolean { |
| 37 | + return a > b; |
| 38 | + ~ |
| 39 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 40 | + ~ |
| 41 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 42 | + } |
| 43 | + |
| 44 | + function f2<T extends {} | undefined | null>(a: T, b: T): boolean { |
| 45 | + return a > b; |
| 46 | + ~ |
| 47 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 48 | + ~ |
| 49 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 50 | + } |
| 51 | + |
| 52 | + function f3<T extends unknown>(a: T, b: T): boolean { |
| 53 | + return a > b; |
| 54 | + ~ |
| 55 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 56 | + ~ |
| 57 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 58 | + } |
| 59 | + |
| 60 | + function f4<T, U extends T>(a: U, b: U): boolean { |
| 61 | + return a > b; |
| 62 | + ~ |
| 63 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 64 | + ~ |
| 65 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 66 | + } |
| 67 | + |
| 68 | + function f5<T extends {} | undefined | null, U extends T>(a: U, b: U): boolean { |
| 69 | + return a > b; |
| 70 | + ~ |
| 71 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 72 | + ~ |
| 73 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 74 | + } |
| 75 | + |
| 76 | + function f6<T extends unknown, U extends T>(a: U, b: U): boolean { |
| 77 | + return a > b; |
| 78 | + ~ |
| 79 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 80 | + ~ |
| 81 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 82 | + } |
| 83 | + |
| 84 | + function f7<T extends {} | undefined, U extends T>(a: U, b: U): boolean { |
| 85 | + return a > b; |
| 86 | + ~ |
| 87 | +!!! error TS18048: 'a' is possibly 'undefined'. |
| 88 | + ~ |
| 89 | +!!! error TS18048: 'b' is possibly 'undefined'. |
| 90 | + } |
| 91 | + |
| 92 | + function f8<T extends {} | null, U extends T>(a: U, b: U): boolean { |
| 93 | + return a > b; |
| 94 | + ~ |
| 95 | +!!! error TS18047: 'a' is possibly 'null'. |
| 96 | + ~ |
| 97 | +!!! error TS18047: 'b' is possibly 'null'. |
| 98 | + } |
| 99 | + |
| 100 | + function f9<T extends undefined | null, U extends T>(a: U, b: U): boolean { |
| 101 | + return a > b; |
| 102 | + ~ |
| 103 | +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. |
| 104 | + ~ |
| 105 | +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. |
| 106 | + } |
| 107 | + |
| 108 | + function f10<T, U>(x: T | U, y: T | U) { |
| 109 | + return x < y; |
| 110 | + ~ |
| 111 | +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. |
| 112 | + ~ |
| 113 | +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 114 | + } |
| 115 | + |
| 116 | + function f11<T, U extends T>(x: T | number, y: U | number) { |
| 117 | + return x < y; |
| 118 | + ~ |
| 119 | +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. |
| 120 | + ~ |
| 121 | +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 122 | + } |
| 123 | + |
| 124 | + function f12<T, U extends T>(x: T | number, y: U | number) { |
| 125 | + if (x === undefined) { |
| 126 | + return false; |
| 127 | + } |
| 128 | + return x < y; |
| 129 | + ~ |
| 130 | +!!! error TS18047: 'x' is possibly 'null'. |
| 131 | + ~ |
| 132 | +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 133 | + } |
| 134 | + |
| 135 | + function f13<T, U extends T | number>(x: U, y: U) { |
| 136 | + if (x === undefined) { |
| 137 | + return false; |
| 138 | + } |
| 139 | + return x < y; |
| 140 | + ~ |
| 141 | +!!! error TS18047: 'x' is possibly 'null'. |
| 142 | + ~ |
| 143 | +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 144 | + } |
| 145 | + |
| 146 | + function f14<T, U>(x: T & U, y: T & U) { |
| 147 | + return x < y; |
| 148 | + ~ |
| 149 | +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. |
| 150 | + ~ |
| 151 | +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. |
| 152 | + } |
| 153 | + |
| 154 | + function f15<T, U extends T>(x: T & number, y: U & number) { |
| 155 | + return x < y; |
| 156 | + } |
| 157 | + |
| 158 | + function f16<T, U extends T>(x: T & U, y: U) { |
| 159 | + if (x === undefined) { |
| 160 | + return false; |
| 161 | + } |
| 162 | + if (y === null) { |
| 163 | + return false; |
| 164 | + } |
| 165 | + return x < y; |
| 166 | + ~ |
| 167 | +!!! error TS18047: 'x' is possibly 'null'. |
| 168 | + ~ |
| 169 | +!!! error TS18048: 'y' is possibly 'undefined'. |
| 170 | + } |
| 171 | + |
| 172 | + |
| 173 | + function compare<T>(a: T, b: T): boolean { |
| 174 | + if (a === undefined) { |
| 175 | + return false; |
| 176 | + } |
| 177 | + if (b === null) { |
| 178 | + return false; |
| 179 | + } |
| 180 | + return a > b; |
| 181 | + ~ |
| 182 | +!!! error TS18047: 'a' is possibly 'null'. |
| 183 | + ~ |
| 184 | +!!! error TS18048: 'b' is possibly 'undefined'. |
| 185 | + } |
| 186 | + |
0 commit comments