MCPcopy Create free account
hub / github.com/microsoft/typescript-go / checkClassLikeDeclaration

Method checkClassLikeDeclaration

internal/checker/checker.go:4276–4374  ·  view source on GitHub ↗
(node *ast.Node)

Source from the content-addressed store, hash-verified

4274}
4275
4276func (c *Checker) checkClassLikeDeclaration(node *ast.Node) {
4277 c.checkGrammarClassLikeDeclaration(node)
4278 c.checkDecorators(node)
4279 c.checkCollisionsForDeclarationName(node, node.Name())
4280 c.checkTypeParameters(node.TypeParameters())
4281 c.checkExportsOnMergedDeclarations(node)
4282 symbol := c.getSymbolOfDeclaration(node)
4283 classType := c.getDeclaredTypeOfSymbol(symbol)
4284 classTypeData := classType.AsInterfaceType()
4285 typeWithThis := c.getTypeWithThisArgument(classType, nil, false)
4286 staticType := c.getTypeOfSymbol(symbol)
4287 c.checkTypeParameterListsIdentical(symbol)
4288 c.checkFunctionOrConstructorSymbol(symbol)
4289 c.checkObjectTypeForDuplicateDeclarations(node, true /*checkPrivateNames*/)
4290
4291 // Only check for reserved static identifiers on non-ambient context.
4292 nodeInAmbientContext := node.Flags&ast.NodeFlagsAmbient != 0
4293 if !nodeInAmbientContext {
4294 c.checkClassForStaticPropertyNameConflicts(node)
4295 }
4296
4297 baseTypeNode := ast.GetExtendsHeritageClauseElement(node)
4298 if baseTypeNode != nil {
4299 c.checkSourceElements(baseTypeNode.TypeArguments())
4300 baseTypes := c.getBaseTypes(classType)
4301 if len(baseTypes) != 0 {
4302 baseType := baseTypes[0]
4303 baseConstructorType := c.getBaseConstructorTypeOfClass(classType)
4304 staticBaseType := c.getApparentType(baseConstructorType)
4305 c.checkBaseTypeAccessibility(staticBaseType, baseTypeNode)
4306 c.checkSourceElement(baseTypeNode.Expression())
4307 if len(baseTypeNode.TypeArguments()) != 0 {
4308 c.checkSourceElements(baseTypeNode.TypeArguments())
4309 for _, constructor := range c.getConstructorsForTypeArguments(staticBaseType, baseTypeNode.TypeArguments(), baseTypeNode) {
4310 if !c.checkTypeArgumentConstraints(baseTypeNode, constructor.typeParameters) {
4311 break
4312 }
4313 }
4314 }
4315 baseWithThis := c.getTypeWithThisArgument(baseType, classTypeData.thisType, false)
4316 if !c.checkTypeAssignableTo(typeWithThis, baseWithThis, nil, nil) {
4317 c.issueMemberSpecificError(node, typeWithThis, baseWithThis, diagnostics.Class_0_incorrectly_extends_base_class_1)
4318 } else {
4319 // Report static side error only when instance type is assignable
4320 c.checkTypeAssignableTo(staticType, c.getTypeWithoutSignatures(staticBaseType), core.OrElse(node.Name(), node), diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1)
4321 }
4322 if baseConstructorType.flags&TypeFlagsTypeVariable != 0 {
4323 if !c.isMixinConstructorType(staticType) {
4324 c.error(core.OrElse(node.Name(), node), diagnostics.A_mixin_class_must_have_a_constructor_with_a_single_rest_parameter_of_type_any)
4325 } else {
4326 constructSignatures := c.getSignaturesOfType(baseConstructorType, SignatureKindConstruct)
4327 if core.Some(constructSignatures, func(signature *Signature) bool {
4328 return signature.flags&SignatureFlagsAbstract != 0
4329 }) && !ast.HasSyntacticModifier(node, ast.ModifierFlagsAbstract) {
4330 c.error(core.OrElse(node.Name(), node), diagnostics.A_mixin_class_that_extends_from_a_type_variable_containing_an_abstract_construct_signature_must_also_be_declared_abstract)
4331 }
4332 }
4333 }

Callers 2

checkClassDeclarationMethod · 0.95
checkClassExpressionMethod · 0.95

Tested by

no test coverage detected