|
| 1 | +file.js(155,13): error TS2322: Type 'undefined' is not assignable to type 'HelperCond<I, string, T | undefined, RegExp, SettingComposedValue<T>[]>'. |
| 2 | +file.js(168,16): error TS2536: Type 'I' cannot be used to index type '{ [s: string]: any; }'. |
| 3 | +file.js(185,9): error TS2322: Type 'Record<string, MyObj[]>' is not assignable to type 'HelperCond<T, string, MyObj[], undefined, Record<string, MyObj[]>>'. |
| 4 | + |
| 5 | + |
| 6 | +==== file.js (3 errors) ==== |
| 7 | + // Adapted from ts-error-deltas repos |
| 8 | + |
| 9 | + /** |
| 10 | + * @template T |
| 11 | + * @template A |
| 12 | + * @template R1 |
| 13 | + * @template B |
| 14 | + * @template R2 |
| 15 | + * @typedef {T extends A ? R1 : T extends B ? R2 : never} HelperCond |
| 16 | + */ |
| 17 | + |
| 18 | + /** |
| 19 | + * @typedef IMessage |
| 20 | + * @property {string} [html] |
| 21 | + * @property {Object[]} [tokens] |
| 22 | + */ |
| 23 | + |
| 24 | + class NewKatex { |
| 25 | + /** |
| 26 | + * @param {string} s |
| 27 | + * @returns {string} |
| 28 | + */ |
| 29 | + render(s) { |
| 30 | + return ""; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @template {string | IMessage} T |
| 35 | + * @param {T} message |
| 36 | + * @returns {T extends string ? string : T extends IMessage ? IMessage : never} |
| 37 | + */ |
| 38 | + renderMessage(message) { |
| 39 | + if (typeof message === 'string') { |
| 40 | + return this.render(message); // Ok |
| 41 | + } |
| 42 | + |
| 43 | + if (!message.html?.trim()) { |
| 44 | + return message; // Ok |
| 45 | + } |
| 46 | + |
| 47 | + if (!message.tokens) { |
| 48 | + message.tokens = []; |
| 49 | + } |
| 50 | + |
| 51 | + message.html = this.render(message.html); |
| 52 | + return message; // Ok |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @template {true | false} T |
| 58 | + * @param {{ dollarSyntax: boolean; parenthesisSyntax: boolean; }} options |
| 59 | + * @param {T} _isMessage |
| 60 | + * @returns {T extends true ? (message: IMessage) => IMessage : T extends false ? (message: string) => string : never} |
| 61 | + */ |
| 62 | + function createKatexMessageRendering(options, _isMessage) { |
| 63 | + const instance = new NewKatex(); |
| 64 | + if (_isMessage) { |
| 65 | + return (/** @type {IMessage} */ message) => instance.renderMessage(message); // Ok |
| 66 | + } |
| 67 | + return (/** @type {string} */ message) => instance.renderMessage(message); // Ok |
| 68 | + } |
| 69 | + |
| 70 | + // File: Rocket.Chat/apps/meteor/app/settings/lib/settings.ts |
| 71 | + |
| 72 | + /** |
| 73 | + * @typedef {Record<any, any>} MyObj |
| 74 | + */ |
| 75 | + |
| 76 | + |
| 77 | + /** |
| 78 | + * @typedef {MyObj} SettingValue |
| 79 | + */ |
| 80 | + |
| 81 | + /** |
| 82 | + * @template {SettingValue} T |
| 83 | + * @typedef {Object} SettingComposedValue |
| 84 | + * @property {string} key |
| 85 | + * @property {SettingValue} value |
| 86 | + */ |
| 87 | + |
| 88 | + /** |
| 89 | + * @callback SettingCallback |
| 90 | + * @param {string} key |
| 91 | + * @param {SettingValue} value |
| 92 | + * @param {boolean} [initialLoad] |
| 93 | + * @returns {void} |
| 94 | + */ |
| 95 | + |
| 96 | + /** @type {{ settings: { [s: string]: any } }} */ |
| 97 | + const Meteor = /** @type {any} */ (undefined); |
| 98 | + /** @type {{ isRegExp(x: unknown): x is RegExp; }} */ |
| 99 | + const _ = /** @type {any} */ (undefined); |
| 100 | + |
| 101 | + /** |
| 102 | + * @param {RegExp} x |
| 103 | + * @returns {void} |
| 104 | + */ |
| 105 | + function takesRegExp(x) { |
| 106 | + return /** @type {any} */ undefined; |
| 107 | + } |
| 108 | + /** |
| 109 | + * @param {string} x |
| 110 | + * @returns {void} |
| 111 | + */ |
| 112 | + function takesString(x) { |
| 113 | + return /** @type {any} */ undefined; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @class NewSettingsBase |
| 118 | + */ |
| 119 | + class NewSettingsBase { |
| 120 | + /** |
| 121 | + * @template {SettingCallback | undefined} C |
| 122 | + * @template {string | RegExp} I |
| 123 | + * @template {SettingValue} T |
| 124 | + * @param {I} _id |
| 125 | + * @param {C} [callback] |
| 126 | + * @returns {HelperCond<C, SettingCallback, void, undefined, HelperCond<I, string, T | undefined, RegExp, SettingComposedValue<T>[]>>} |
| 127 | + */ |
| 128 | + newGet(_id, callback) { |
| 129 | + if (callback !== undefined) { |
| 130 | + if (!Meteor.settings) { |
| 131 | + return; // Ok |
| 132 | + } |
| 133 | + if (_id === '*') { |
| 134 | + return Object.keys(Meteor.settings).forEach((key) => { |
| 135 | + const value = Meteor.settings[key]; |
| 136 | + callback(key, value); |
| 137 | + }); |
| 138 | + } |
| 139 | + if (_.isRegExp(_id) && Meteor.settings) { |
| 140 | + return Object.keys(Meteor.settings).forEach((key) => { |
| 141 | + if (!_id.test(key)) { |
| 142 | + return; |
| 143 | + } |
| 144 | + const value = Meteor.settings[key]; |
| 145 | + callback(key, value); |
| 146 | + }); |
| 147 | + } |
| 148 | + |
| 149 | + if (typeof _id === 'string') { |
| 150 | + const value = Meteor.settings[_id]; |
| 151 | + if (value != null) { |
| 152 | + callback(_id, Meteor.settings[_id]); |
| 153 | + } |
| 154 | + return; // Ok |
| 155 | + } |
| 156 | + |
| 157 | + return; // Ok, needed for exhaustiveness check |
| 158 | + } |
| 159 | + |
| 160 | + if (!Meteor.settings) { |
| 161 | + return undefined; // Error |
| 162 | + ~~~~~~ |
| 163 | +!!! error TS2322: Type 'undefined' is not assignable to type 'HelperCond<I, string, T | undefined, RegExp, SettingComposedValue<T>[]>'. |
| 164 | + } |
| 165 | + |
| 166 | + if (_.isRegExp(_id)) { |
| 167 | + return Object.keys(Meteor.settings).reduce((/** @type {SettingComposedValue<T>[]} */ items, key) => { |
| 168 | + const value = Meteor.settings[key]; |
| 169 | + if (_id.test(key)) { |
| 170 | + items.push({ key, value }); |
| 171 | + } |
| 172 | + return items; |
| 173 | + }, []); // Ok |
| 174 | + } |
| 175 | + |
| 176 | + return Meteor.settings?.[_id]; // Error |
| 177 | + ~~~~~~~~~~~~~~~~~~~~~~ |
| 178 | +!!! error TS2536: Type 'I' cannot be used to index type '{ [s: string]: any; }'. |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + // File: Rocket.Chat/apps/meteor/app/ui-utils/client/lib/messageBox.ts |
| 183 | + |
| 184 | + /** |
| 185 | + * @typedef {MyObj} MessageBoxAction |
| 186 | + */ |
| 187 | + |
| 188 | + /** |
| 189 | + * @template {string | undefined} T |
| 190 | + * @param {T} group |
| 191 | + * @returns {HelperCond<T, string, MessageBoxAction[], undefined, Record<string, MessageBoxAction[]>>} |
| 192 | + */ |
| 193 | + function getWithBug(group) { |
| 194 | + if (!group) { |
| 195 | + return /** @type {Record<string, MessageBoxAction[]>} */({}); // Error |
| 196 | + ~~~~~~ |
| 197 | +!!! error TS2322: Type 'Record<string, MyObj[]>' is not assignable to type 'HelperCond<T, string, MyObj[], undefined, Record<string, MyObj[]>>'. |
| 198 | + } |
| 199 | + return /** @type {MessageBoxAction[]} */([]); // Ok |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * @template {string | undefined} T |
| 204 | + * @param {T} group |
| 205 | + * @returns {HelperCond<T, string, MessageBoxAction[], undefined, Record<string, MessageBoxAction[]>>} |
| 206 | + */ |
| 207 | + function getWithoutBug(group) { |
| 208 | + if (group === undefined) { |
| 209 | + return /** @type {Record<string, MessageBoxAction[]>} */({}); // Ok |
| 210 | + } |
| 211 | + return /** @type {MessageBoxAction[]} */([]); // Ok |
| 212 | + } |
| 213 | + |
| 214 | + // File: Rocket.Chat/apps/meteor/ee/server/lib/engagementDashboard/date.ts |
| 215 | + |
| 216 | + /** |
| 217 | + * @param {string} x |
| 218 | + * @returns {Date} |
| 219 | + */ |
| 220 | + function mapDateForAPI(x) { |
| 221 | + return /** @type {any} */ (undefined); |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * @template {string | undefined} T |
| 226 | + * @param {string} start |
| 227 | + * @param {T} [end] |
| 228 | + * @returns {HelperCond<T, string, { start: Date, end: Date }, undefined, { start: Date, end: undefined }>} |
| 229 | + */ |
| 230 | + function transformDatesForAPI(start, end) { |
| 231 | + return end !== undefined ? |
| 232 | + { |
| 233 | + start: mapDateForAPI(start), |
| 234 | + end: mapDateForAPI(end), |
| 235 | + } : |
| 236 | + { |
| 237 | + start: mapDateForAPI(start), |
| 238 | + end: undefined |
| 239 | + }; |
| 240 | + } |
| 241 | + |
| 242 | + // File: Rocket.Chat/packages/agenda/src/Agenda.ts |
| 243 | + |
| 244 | + /** |
| 245 | + * @typedef {MyObj} RepeatOptions |
| 246 | + */ |
| 247 | + |
| 248 | + /** |
| 249 | + * @typedef {MyObj} Job |
| 250 | + */ |
| 251 | + |
| 252 | + /** |
| 253 | + * @typedef {Object} IJob |
| 254 | + * @property {MyObj} data |
| 255 | + */ |
| 256 | + class NewAgenda { |
| 257 | + /** |
| 258 | + * @param {string | number} interval |
| 259 | + * @param {string} name |
| 260 | + * @param {IJob['data']} data |
| 261 | + * @param {RepeatOptions} options |
| 262 | + * @returns {Promise<Job>} |
| 263 | + */ |
| 264 | + async _createIntervalJob(interval, name, data, options) { |
| 265 | + return /** @type {any} */ (undefined); |
| 266 | + } |
| 267 | + |
| 268 | + /** |
| 269 | + * @param {string | number} interval |
| 270 | + * @param {string[]} names |
| 271 | + * @param {IJob['data']} data |
| 272 | + * @param {RepeatOptions} options |
| 273 | + * @returns {Promise<Job[]> | undefined} |
| 274 | + */ |
| 275 | + _createIntervalJobs(interval, names, data, options) { |
| 276 | + return undefined; |
| 277 | + } |
| 278 | + |
| 279 | + /** |
| 280 | + * @template {string | string[]} T |
| 281 | + * @param {string | number} interval |
| 282 | + * @param {T} name |
| 283 | + * @param {IJob['data']} data |
| 284 | + * @param {RepeatOptions} options |
| 285 | + * @returns {Promise<HelperCond<T, string, Job, string[], Job[] | undefined>>} |
| 286 | + */ |
| 287 | + async newEvery(interval, name, data, options) { |
| 288 | + if (typeof name === 'string') { |
| 289 | + return this._createIntervalJob(interval, name, data, options); // Ok |
| 290 | + } |
| 291 | + |
| 292 | + if (Array.isArray(name)) { |
| 293 | + return this._createIntervalJobs(interval, name, data, options); // Ok |
| 294 | + } |
| 295 | + |
| 296 | + throw new Error('Unexpected error: Invalid job name(s)'); |
| 297 | + } |
| 298 | + } |
| 299 | + |
| 300 | + // File: angular/packages/common/src/pipes/case_conversion_pipes.ts |
| 301 | + |
| 302 | + /** |
| 303 | + * @template {string | null | undefined} T |
| 304 | + * @param {T} value |
| 305 | + * @returns {HelperCond<T, string, string, null | undefined, null>} |
| 306 | + */ |
| 307 | + function transform1(value) { |
| 308 | + if (value == null) return null; // Ok |
| 309 | + if (typeof value !== 'string') { |
| 310 | + throw new Error(); |
| 311 | + } |
| 312 | + return value.toLowerCase(); // Ok |
| 313 | + } |
| 314 | + |
0 commit comments