(indexInfos, keyType)
| 59445 | return ts.find(indexInfos, function (info) { return info.keyType === keyType; }); |
| 59446 | } |
| 59447 | function findApplicableIndexInfo(indexInfos, keyType) { |
| 59448 | // Index signatures for type 'string' are considered only when no other index signatures apply. |
| 59449 | var stringIndexInfo; |
| 59450 | var applicableInfo; |
| 59451 | var applicableInfos; |
| 59452 | for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) { |
| 59453 | var info = indexInfos_3[_i]; |
| 59454 | if (info.keyType === stringType) { |
| 59455 | stringIndexInfo = info; |
| 59456 | } |
| 59457 | else if (isApplicableIndexType(keyType, info.keyType)) { |
| 59458 | if (!applicableInfo) { |
| 59459 | applicableInfo = info; |
| 59460 | } |
| 59461 | else { |
| 59462 | (applicableInfos || (applicableInfos = [applicableInfo])).push(info); |
| 59463 | } |
| 59464 | } |
| 59465 | } |
| 59466 | // When more than one index signature is applicable we create a synthetic IndexInfo. Instead of computing |
| 59467 | // the intersected key type, we just use unknownType for the key type as nothing actually depends on the |
| 59468 | // keyType property of the returned IndexInfo. |
| 59469 | return applicableInfos ? createIndexInfo(unknownType, getIntersectionType(ts.map(applicableInfos, function (info) { return info.type; })), ts.reduceLeft(applicableInfos, function (isReadonly, info) { return isReadonly && info.isReadonly; }, /*initial*/ true)) : |
| 59470 | applicableInfo ? applicableInfo : |
| 59471 | stringIndexInfo && isApplicableIndexType(keyType, stringType) ? stringIndexInfo : |
| 59472 | undefined; |
| 59473 | } |
| 59474 | function isApplicableIndexType(source, target) { |
| 59475 | // A 'string' index signature applies to types assignable to 'string' or 'number', and a 'number' index |
| 59476 | // signature applies to types assignable to 'number', `${number}` and numeric string literal types. |
no test coverage detected