* Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include * references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the * declared type. Instantiations are cached u
(node, symbol)
| 60317 | * declared type. Instantiations are cached using the type identities of the type arguments as the key. |
| 60318 | */ |
| 60319 | function getTypeFromTypeAliasReference(node, symbol) { |
| 60320 | if (ts.getCheckFlags(symbol) & 1048576 /* CheckFlags.Unresolved */) { |
| 60321 | var typeArguments = typeArgumentsFromTypeReferenceNode(node); |
| 60322 | var id = getAliasId(symbol, typeArguments); |
| 60323 | var errorType_1 = errorTypes.get(id); |
| 60324 | if (!errorType_1) { |
| 60325 | errorType_1 = createIntrinsicType(1 /* TypeFlags.Any */, "error"); |
| 60326 | errorType_1.aliasSymbol = symbol; |
| 60327 | errorType_1.aliasTypeArguments = typeArguments; |
| 60328 | errorTypes.set(id, errorType_1); |
| 60329 | } |
| 60330 | return errorType_1; |
| 60331 | } |
| 60332 | var type = getDeclaredTypeOfSymbol(symbol); |
| 60333 | var typeParameters = getSymbolLinks(symbol).typeParameters; |
| 60334 | if (typeParameters) { |
| 60335 | var numTypeArguments = ts.length(node.typeArguments); |
| 60336 | var minTypeArgumentCount = getMinTypeArgumentCount(typeParameters); |
| 60337 | if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) { |
| 60338 | error(node, minTypeArgumentCount === typeParameters.length ? |
| 60339 | ts.Diagnostics.Generic_type_0_requires_1_type_argument_s : |
| 60340 | ts.Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, symbolToString(symbol), minTypeArgumentCount, typeParameters.length); |
| 60341 | return errorType; |
| 60342 | } |
| 60343 | // We refrain from associating a local type alias with an instantiation of a top-level type alias |
| 60344 | // because the local alias may end up being referenced in an inferred return type where it is not |
| 60345 | // accessible--which in turn may lead to a large structural expansion of the type when generating |
| 60346 | // a .d.ts file. See #43622 for an example. |
| 60347 | var aliasSymbol = getAliasSymbolForTypeNode(node); |
| 60348 | var newAliasSymbol = aliasSymbol && (isLocalTypeAlias(symbol) || !isLocalTypeAlias(aliasSymbol)) ? aliasSymbol : undefined; |
| 60349 | return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), newAliasSymbol, getTypeArgumentsForAliasSymbol(newAliasSymbol)); |
| 60350 | } |
| 60351 | return checkNoTypeArguments(node, symbol) ? type : errorType; |
| 60352 | } |
| 60353 | function isLocalTypeAlias(symbol) { |
| 60354 | var _a; |
| 60355 | var declaration = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isTypeAlias); |
no test coverage detected
searching dependent graphs…