(symbol, typeParameters)
| 66980 | // instantiations of the generic type for type arguments with known relations. The function |
| 66981 | // returns the emptyArray singleton when invoked recursively for the given generic type. |
| 66982 | function getVariancesWorker(symbol, typeParameters) { |
| 66983 | if (typeParameters === void 0) { typeParameters = ts.emptyArray; } |
| 66984 | var links = getSymbolLinks(symbol); |
| 66985 | if (!links.variances) { |
| 66986 | ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* tracing.Phase.CheckTypes */, "getVariancesWorker", { arity: typeParameters.length, id: getTypeId(getDeclaredTypeOfSymbol(symbol)) }); |
| 66987 | links.variances = ts.emptyArray; |
| 66988 | var variances = []; |
| 66989 | var _loop_22 = function (tp) { |
| 66990 | var modifiers = getVarianceModifiers(tp); |
| 66991 | var variance = modifiers & 65536 /* ModifierFlags.Out */ ? |
| 66992 | modifiers & 32768 /* ModifierFlags.In */ ? 0 /* VarianceFlags.Invariant */ : 1 /* VarianceFlags.Covariant */ : |
| 66993 | modifiers & 32768 /* ModifierFlags.In */ ? 2 /* VarianceFlags.Contravariant */ : undefined; |
| 66994 | if (variance === undefined) { |
| 66995 | var unmeasurable_1 = false; |
| 66996 | var unreliable_1 = false; |
| 66997 | var oldHandler = outofbandVarianceMarkerHandler; |
| 66998 | outofbandVarianceMarkerHandler = function (onlyUnreliable) { return onlyUnreliable ? unreliable_1 = true : unmeasurable_1 = true; }; |
| 66999 | // We first compare instantiations where the type parameter is replaced with |
| 67000 | // marker types that have a known subtype relationship. From this we can infer |
| 67001 | // invariance, covariance, contravariance or bivariance. |
| 67002 | var typeWithSuper = createMarkerType(symbol, tp, markerSuperType); |
| 67003 | var typeWithSub = createMarkerType(symbol, tp, markerSubType); |
| 67004 | variance = (isTypeAssignableTo(typeWithSub, typeWithSuper) ? 1 /* VarianceFlags.Covariant */ : 0) | |
| 67005 | (isTypeAssignableTo(typeWithSuper, typeWithSub) ? 2 /* VarianceFlags.Contravariant */ : 0); |
| 67006 | // If the instantiations appear to be related bivariantly it may be because the |
| 67007 | // type parameter is independent (i.e. it isn't witnessed anywhere in the generic |
| 67008 | // type). To determine this we compare instantiations where the type parameter is |
| 67009 | // replaced with marker types that are known to be unrelated. |
| 67010 | if (variance === 3 /* VarianceFlags.Bivariant */ && isTypeAssignableTo(createMarkerType(symbol, tp, markerOtherType), typeWithSuper)) { |
| 67011 | variance = 4 /* VarianceFlags.Independent */; |
| 67012 | } |
| 67013 | outofbandVarianceMarkerHandler = oldHandler; |
| 67014 | if (unmeasurable_1 || unreliable_1) { |
| 67015 | if (unmeasurable_1) { |
| 67016 | variance |= 8 /* VarianceFlags.Unmeasurable */; |
| 67017 | } |
| 67018 | if (unreliable_1) { |
| 67019 | variance |= 16 /* VarianceFlags.Unreliable */; |
| 67020 | } |
| 67021 | } |
| 67022 | } |
| 67023 | variances.push(variance); |
| 67024 | }; |
| 67025 | for (var _i = 0, typeParameters_1 = typeParameters; _i < typeParameters_1.length; _i++) { |
| 67026 | var tp = typeParameters_1[_i]; |
| 67027 | _loop_22(tp); |
| 67028 | } |
| 67029 | links.variances = variances; |
| 67030 | ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop(); |
| 67031 | } |
| 67032 | return links.variances; |
| 67033 | } |
| 67034 | function createMarkerType(symbol, source, target) { |
| 67035 | var mapper = makeUnaryTypeMapper(source, target); |
| 67036 | var type = getDeclaredTypeOfSymbol(symbol); |
no test coverage detected