MCPcopy Index your code
hub / github.com/nodejs/node / getWidenedTypeForAssignmentDeclaration

Function getWidenedTypeForAssignmentDeclaration

test/fixtures/snapshot/typescript.js:56156–56230  ·  view source on GitHub ↗
(symbol, resolvedSymbol)

Source from the content-addressed store, hash-verified

56154 return getFlowTypeOfReference(reference, autoType, initialType);
56155 }
56156 function getWidenedTypeForAssignmentDeclaration(symbol, resolvedSymbol) {
56157 // function/class/{} initializers are themselves containers, so they won't merge in the same way as other initializers
56158 var container = ts.getAssignedExpandoInitializer(symbol.valueDeclaration);
56159 if (container) {
56160 var tag = ts.getJSDocTypeTag(container);
56161 if (tag && tag.typeExpression) {
56162 return getTypeFromTypeNode(tag.typeExpression);
56163 }
56164 var containerObjectType = symbol.valueDeclaration && getJSContainerObjectType(symbol.valueDeclaration, symbol, container);
56165 return containerObjectType || getWidenedLiteralType(checkExpressionCached(container));
56166 }
56167 var type;
56168 var definedInConstructor = false;
56169 var definedInMethod = false;
56170 // We use control flow analysis to determine the type of the property if the property qualifies as a constructor
56171 // declared property and the resulting control flow type isn't just undefined or null.
56172 if (isConstructorDeclaredProperty(symbol)) {
56173 type = getFlowTypeInConstructor(symbol, getDeclaringConstructor(symbol));
56174 }
56175 if (!type) {
56176 var types = void 0;
56177 if (symbol.declarations) {
56178 var jsdocType = void 0;
56179 for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
56180 var declaration = _a[_i];
56181 var expression = (ts.isBinaryExpression(declaration) || ts.isCallExpression(declaration)) ? declaration :
56182 ts.isAccessExpression(declaration) ? ts.isBinaryExpression(declaration.parent) ? declaration.parent : declaration :
56183 undefined;
56184 if (!expression) {
56185 continue; // Non-assignment declaration merged in (eg, an Identifier to mark the thing as a namespace) - skip over it and pull type info from elsewhere
56186 }
56187 var kind = ts.isAccessExpression(expression)
56188 ? ts.getAssignmentDeclarationPropertyAccessKind(expression)
56189 : ts.getAssignmentDeclarationKind(expression);
56190 if (kind === 4 /* AssignmentDeclarationKind.ThisProperty */ || ts.isBinaryExpression(expression) && isPossiblyAliasedThisProperty(expression, kind)) {
56191 if (isDeclarationInConstructor(expression)) {
56192 definedInConstructor = true;
56193 }
56194 else {
56195 definedInMethod = true;
56196 }
56197 }
56198 if (!ts.isCallExpression(expression)) {
56199 jsdocType = getAnnotatedTypeForAssignmentDeclaration(jsdocType, expression, symbol, declaration);
56200 }
56201 if (!jsdocType) {
56202 (types || (types = [])).push((ts.isBinaryExpression(expression) || ts.isCallExpression(expression)) ? getInitializerTypeFromAssignmentDeclaration(symbol, resolvedSymbol, expression, kind) : neverType);
56203 }
56204 }
56205 type = jsdocType;
56206 }
56207 if (!type) {
56208 if (!ts.length(types)) {
56209 return errorType; // No types from any declarations :(
56210 }
56211 var constructorTypes = definedInConstructor && symbol.declarations ? getConstructorDefinedThisAssignmentTypes(types, symbol.declarations) : undefined;
56212 // use only the constructor types unless they were only assigned null | undefined (including widening variants)
56213 if (definedInMethod) {

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…