(contextualType, node, contextFlags)
| 72922 | // If the given contextual type contains instantiable types and if a mapper representing |
| 72923 | // return type inferences is available, instantiate those types using that mapper. |
| 72924 | function instantiateContextualType(contextualType, node, contextFlags) { |
| 72925 | if (contextualType && maybeTypeOfKind(contextualType, 465829888 /* TypeFlags.Instantiable */)) { |
| 72926 | var inferenceContext = getInferenceContext(node); |
| 72927 | // If no inferences have been made, nothing is gained from instantiating as type parameters |
| 72928 | // would just be replaced with their defaults similar to the apparent type. |
| 72929 | if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) { |
| 72930 | // For contextual signatures we incorporate all inferences made so far, e.g. from return |
| 72931 | // types as well as arguments to the left in a function call. |
| 72932 | if (contextFlags && contextFlags & 1 /* ContextFlags.Signature */) { |
| 72933 | return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper); |
| 72934 | } |
| 72935 | // For other purposes (e.g. determining whether to produce literal types) we only |
| 72936 | // incorporate inferences made from the return type in a function call. We remove |
| 72937 | // the 'boolean' type from the contextual type such that contextually typed boolean |
| 72938 | // literals actually end up widening to 'boolean' (see #48363). |
| 72939 | if (inferenceContext.returnMapper) { |
| 72940 | var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper); |
| 72941 | return type.flags & 1048576 /* TypeFlags.Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ? |
| 72942 | filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) : |
| 72943 | type; |
| 72944 | } |
| 72945 | } |
| 72946 | } |
| 72947 | return contextualType; |
| 72948 | } |
| 72949 | // This function is similar to instantiateType, except that (a) it only instantiates types that |
| 72950 | // are classified as instantiable (i.e. it doesn't instantiate object types), and (b) it performs |
| 72951 | // no reductions on instantiated union types. |
no test coverage detected