@@ -3752,16 +3752,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3752
3752
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
3753
3753
if (meaning & SymbolFlags.Value) {
3754
3754
if (isPrimitiveTypeName(name)) {
3755
- // const grandparent = errorLocation.parent.parent;
3756
- // const parentOfGrandparent = grandparent.parent;
3757
- if (isExtendedByInterface(errorLocation)) {
3758
- error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3759
- }
3760
- else if (isExtendedByClass(errorLocation)) {
3761
- error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3762
- }
3763
- else if (isImplementedByClass(errorLocation)) {
3764
- error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3755
+ const grandparent = errorLocation.parent.parent;
3756
+ if (grandparent && grandparent.parent && isHeritageClause(grandparent)) {
3757
+ const heritageKind = grandparent.token;
3758
+ const containerKind = grandparent.parent.kind;
3759
+ if (containerKind === SyntaxKind.InterfaceDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3760
+ error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3761
+ }
3762
+ else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3763
+ error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3764
+ }
3765
+ else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ImplementsKeyword) {
3766
+ error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3767
+ }
3765
3768
}
3766
3769
else {
3767
3770
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3786,39 +3789,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3786
3789
}
3787
3790
return false;
3788
3791
}
3789
-
3790
- function isExtendedByInterface(node: Node): boolean {
3791
- const grandparent = node.parent.parent;
3792
- const parentOfGrandparent = grandparent.parent;
3793
- if (grandparent && parentOfGrandparent) {
3794
- const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3795
- const isInterface = isInterfaceDeclaration(parentOfGrandparent);
3796
- return isExtending && isInterface;
3797
- }
3798
- return false;
3799
- }
3800
-
3801
- function isExtendedByClass(node: Node): boolean {
3802
- const grandparent = node.parent.parent;
3803
- const parentOfGrandparent = grandparent.parent;
3804
- if (grandparent && parentOfGrandparent) {
3805
- const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3806
- const isClass = isClassDeclaration(parentOfGrandparent);
3807
- return isExtending && isClass;
3808
- }
3809
- return false;
3810
- }
3811
-
3812
- function isImplementedByClass(node: Node): boolean {
3813
- const grandparent = node.parent.parent;
3814
- const parentOfGrandparent = grandparent.parent;
3815
- if (grandparent && parentOfGrandparent) {
3816
- const isImplementing = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ImplementsKeyword;
3817
- const isClass = isClassDeclaration(parentOfGrandparent);
3818
- return isImplementing && isClass;
3819
- }
3820
- return false;
3821
- }
3822
3792
3823
3793
function maybeMappedType(node: Node, symbol: Symbol) {
3824
3794
const container = findAncestor(node.parent, n => isComputedPropertyName(n) || isPropertySignature(n) ? false : isTypeLiteralNode(n) || "quit") as TypeLiteralNode | undefined;
0 commit comments