* The base constructor of a class can resolve to * * undefinedType if the class has no extends clause, * * unknownType if an error occurred during resolution of the extends expression, * * nullType if the extends expression is the null value, * * anyType if the ex
(type)
| 57098 | * * an object type with at least one construct signature. |
| 57099 | */ |
| 57100 | function getBaseConstructorTypeOfClass(type) { |
| 57101 | if (!type.resolvedBaseConstructorType) { |
| 57102 | var decl = ts.getClassLikeDeclarationOfSymbol(type.symbol); |
| 57103 | var extended = decl && ts.getEffectiveBaseTypeNode(decl); |
| 57104 | var baseTypeNode = getBaseTypeNodeOfClass(type); |
| 57105 | if (!baseTypeNode) { |
| 57106 | return type.resolvedBaseConstructorType = undefinedType; |
| 57107 | } |
| 57108 | if (!pushTypeResolution(type, 1 /* TypeSystemPropertyName.ResolvedBaseConstructorType */)) { |
| 57109 | return errorType; |
| 57110 | } |
| 57111 | var baseConstructorType = checkExpression(baseTypeNode.expression); |
| 57112 | if (extended && baseTypeNode !== extended) { |
| 57113 | ts.Debug.assert(!extended.typeArguments); // Because this is in a JS file, and baseTypeNode is in an @extends tag |
| 57114 | checkExpression(extended.expression); |
| 57115 | } |
| 57116 | if (baseConstructorType.flags & (524288 /* TypeFlags.Object */ | 2097152 /* TypeFlags.Intersection */)) { |
| 57117 | // Resolving the members of a class requires us to resolve the base class of that class. |
| 57118 | // We force resolution here such that we catch circularities now. |
| 57119 | resolveStructuredTypeMembers(baseConstructorType); |
| 57120 | } |
| 57121 | if (!popTypeResolution()) { |
| 57122 | error(type.symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol)); |
| 57123 | return type.resolvedBaseConstructorType = errorType; |
| 57124 | } |
| 57125 | if (!(baseConstructorType.flags & 1 /* TypeFlags.Any */) && baseConstructorType !== nullWideningType && !isConstructorType(baseConstructorType)) { |
| 57126 | var err = error(baseTypeNode.expression, ts.Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType)); |
| 57127 | if (baseConstructorType.flags & 262144 /* TypeFlags.TypeParameter */) { |
| 57128 | var constraint = getConstraintFromTypeParameter(baseConstructorType); |
| 57129 | var ctorReturn = unknownType; |
| 57130 | if (constraint) { |
| 57131 | var ctorSig = getSignaturesOfType(constraint, 1 /* SignatureKind.Construct */); |
| 57132 | if (ctorSig[0]) { |
| 57133 | ctorReturn = getReturnTypeOfSignature(ctorSig[0]); |
| 57134 | } |
| 57135 | } |
| 57136 | if (baseConstructorType.symbol.declarations) { |
| 57137 | ts.addRelatedInfo(err, ts.createDiagnosticForNode(baseConstructorType.symbol.declarations[0], ts.Diagnostics.Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1, symbolToString(baseConstructorType.symbol), typeToString(ctorReturn))); |
| 57138 | } |
| 57139 | } |
| 57140 | return type.resolvedBaseConstructorType = errorType; |
| 57141 | } |
| 57142 | type.resolvedBaseConstructorType = baseConstructorType; |
| 57143 | } |
| 57144 | return type.resolvedBaseConstructorType; |
| 57145 | } |
| 57146 | function getImplementsTypes(type) { |
| 57147 | var resolvedImplementsTypes = ts.emptyArray; |
| 57148 | if (type.symbol.declarations) { |
no test coverage detected
searching dependent graphs…