@@ -3788,16 +3788,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3788
3788
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
3789
3789
if (meaning & SymbolFlags.Value) {
3790
3790
if (isPrimitiveTypeName(name)) {
3791
- // const grandparent = errorLocation.parent.parent;
3792
- // const parentOfGrandparent = grandparent.parent;
3793
- if (isExtendedByInterface(errorLocation)) {
3794
- error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3795
- }
3796
- else if (isExtendedByClass(errorLocation)) {
3797
- error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3798
- }
3799
- else if (isImplementedByClass(errorLocation)) {
3800
- error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3791
+ const grandparent = errorLocation.parent.parent;
3792
+ if (grandparent && grandparent.parent && isHeritageClause(grandparent)) {
3793
+ const heritageKind = grandparent.token;
3794
+ const containerKind = grandparent.parent.kind;
3795
+ if (containerKind === SyntaxKind.InterfaceDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3796
+ error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3797
+ }
3798
+ else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3799
+ error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3800
+ }
3801
+ else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ImplementsKeyword) {
3802
+ error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3803
+ }
3801
3804
}
3802
3805
else {
3803
3806
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3822,39 +3825,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3822
3825
}
3823
3826
return false;
3824
3827
}
3825
-
3826
- function isExtendedByInterface(node: Node): boolean {
3827
- const grandparent = node.parent.parent;
3828
- const parentOfGrandparent = grandparent.parent;
3829
- if (grandparent && parentOfGrandparent) {
3830
- const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3831
- const isInterface = isInterfaceDeclaration(parentOfGrandparent);
3832
- return isExtending && isInterface;
3833
- }
3834
- return false;
3835
- }
3836
-
3837
- function isExtendedByClass(node: Node): boolean {
3838
- const grandparent = node.parent.parent;
3839
- const parentOfGrandparent = grandparent.parent;
3840
- if (grandparent && parentOfGrandparent) {
3841
- const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3842
- const isClass = isClassDeclaration(parentOfGrandparent);
3843
- return isExtending && isClass;
3844
- }
3845
- return false;
3846
- }
3847
-
3848
- function isImplementedByClass(node: Node): boolean {
3849
- const grandparent = node.parent.parent;
3850
- const parentOfGrandparent = grandparent.parent;
3851
- if (grandparent && parentOfGrandparent) {
3852
- const isImplementing = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ImplementsKeyword;
3853
- const isClass = isClassDeclaration(parentOfGrandparent);
3854
- return isImplementing && isClass;
3855
- }
3856
- return false;
3857
- }
3858
3828
3859
3829
function maybeMappedType(node: Node, symbol: Symbol) {
3860
3830
const container = findAncestor(node.parent, n => isComputedPropertyName(n) || isPropertySignature(n) ? false : isTypeLiteralNode(n) || "quit") as TypeLiteralNode | undefined;
0 commit comments