(root, mapper, aliasSymbol, aliasTypeArguments)
| 62529 | return isTypicalNondistributiveConditional(root) && isTupleType(type) ? getTypeArguments(type)[0] : type; |
| 62530 | } |
| 62531 | function getConditionalType(root, mapper, aliasSymbol, aliasTypeArguments) { |
| 62532 | var result; |
| 62533 | var extraTypes; |
| 62534 | var tailCount = 0; |
| 62535 | var _loop_18 = function () { |
| 62536 | if (tailCount === 1000) { |
| 62537 | error(currentNode, ts.Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite); |
| 62538 | result = errorType; |
| 62539 | return "break"; |
| 62540 | } |
| 62541 | var isUnwrapped = isTypicalNondistributiveConditional(root); |
| 62542 | var checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable(root.checkType)), mapper); |
| 62543 | var checkTypeInstantiable = isGenericType(checkType); |
| 62544 | var extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper); |
| 62545 | if (checkType === wildcardType || extendsType === wildcardType) { |
| 62546 | return { value: wildcardType }; |
| 62547 | } |
| 62548 | var combinedMapper = void 0; |
| 62549 | if (root.inferTypeParameters) { |
| 62550 | // When we're looking at making an inference for an infer type, when we get its constraint, it'll automagically be |
| 62551 | // instantiated with the context, so it doesn't need the mapper for the inference contex - however the constraint |
| 62552 | // may refer to another _root_, _uncloned_ `infer` type parameter [1], or to something mapped by `mapper` [2]. |
| 62553 | // [1] Eg, if we have `Foo<T, U extends T>` and `Foo<number, infer B>` - `B` is constrained to `T`, which, in turn, has been instantiated |
| 62554 | // as `number` |
| 62555 | // Conversely, if we have `Foo<infer A, infer B>`, `B` is still constrained to `T` and `T` is instantiated as `A` |
| 62556 | // [2] Eg, if we have `Foo<T, U extends T>` and `Foo<Q, infer B>` where `Q` is mapped by `mapper` into `number` - `B` is constrained to `T` |
| 62557 | // which is in turn instantiated as `Q`, which is in turn instantiated as `number`. |
| 62558 | // So we need to: |
| 62559 | // * Clone the type parameters so their constraints can be instantiated in the context of `mapper` (otherwise theyd only get inference context information) |
| 62560 | // * Set the clones to both map the conditional's enclosing `mapper` and the original params |
| 62561 | // * instantiate the extends type with the clones |
| 62562 | // * incorporate all of the component mappers into the combined mapper for the true and false members |
| 62563 | // This means we have three mappers that need applying: |
| 62564 | // * The original `mapper` used to create this conditional |
| 62565 | // * The mapper that maps the old root type parameter to the clone (`freshMapper`) |
| 62566 | // * The mapper that maps the clone to its inference result (`context.mapper`) |
| 62567 | var freshParams = ts.sameMap(root.inferTypeParameters, maybeCloneTypeParameter); |
| 62568 | var freshMapper = freshParams !== root.inferTypeParameters ? createTypeMapper(root.inferTypeParameters, freshParams) : undefined; |
| 62569 | var context = createInferenceContext(freshParams, /*signature*/ undefined, 0 /* InferenceFlags.None */); |
| 62570 | if (freshMapper) { |
| 62571 | var freshCombinedMapper = combineTypeMappers(mapper, freshMapper); |
| 62572 | for (var _i = 0, freshParams_1 = freshParams; _i < freshParams_1.length; _i++) { |
| 62573 | var p = freshParams_1[_i]; |
| 62574 | if (root.inferTypeParameters.indexOf(p) === -1) { |
| 62575 | p.mapper = freshCombinedMapper; |
| 62576 | } |
| 62577 | } |
| 62578 | } |
| 62579 | // We skip inference of the possible `infer` types unles the `extendsType` _is_ an infer type |
| 62580 | // if it was, it's trivial to say that extendsType = checkType, however such a pattern is used to |
| 62581 | // "reset" the type being build up during constraint calculation and avoid making an apparently "infinite" constraint |
| 62582 | // so in those cases we refain from performing inference and retain the uninfered type parameter |
| 62583 | if (!checkTypeInstantiable || !ts.some(root.inferTypeParameters, function (t) { return t === extendsType; })) { |
| 62584 | // We don't want inferences from constraints as they may cause us to eagerly resolve the |
| 62585 | // conditional type instead of deferring resolution. Also, we always want strict function |
| 62586 | // types rules (i.e. proper contravariance) for inferences. |
| 62587 | inferTypes(context.inferences, checkType, instantiateType(extendsType, freshMapper), 512 /* InferencePriority.NoConstraints */ | 1024 /* InferencePriority.AlwaysStrict */); |
| 62588 | } |
no test coverage detected
searching dependent graphs…