From f00dfe743b78862fa8052ca312305d242989b297 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 20 Jun 2025 23:48:40 -0700 Subject: [PATCH] Port TS PR 60490 --- internal/checker/checker.go | 4 +- .../classImplementsPrimitive.errors.txt | 20 ++++++++- .../classImplementsPrimitive.errors.txt.diff | 44 ------------------- .../classExtendingPrimitive.errors.txt | 20 ++++++++- .../classExtendingPrimitive.errors.txt.diff | 44 ------------------- 5 files changed, 40 insertions(+), 92 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt.diff diff --git a/internal/checker/checker.go b/internal/checker/checker.go index a20cd5ddd8..0a98bb16ca 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -1600,9 +1600,9 @@ func (c *Checker) checkAndReportErrorForUsingTypeAsValue(errorLocation *ast.Node containerKind := grandparent.Parent.Kind if containerKind == ast.KindInterfaceDeclaration && heritageKind == ast.KindExtendsKeyword { c.error(errorLocation, diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, name) - } else if containerKind == ast.KindClassDeclaration && heritageKind == ast.KindExtendsKeyword { + } else if ast.IsClassLike(grandparent.Parent) && heritageKind == ast.KindExtendsKeyword { c.error(errorLocation, diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, name) - } else if containerKind == ast.KindClassDeclaration && heritageKind == ast.KindImplementsKeyword { + } else if ast.IsClassLike(grandparent.Parent) && heritageKind == ast.KindImplementsKeyword { c.error(errorLocation, diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, name) } } else { diff --git a/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt b/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt index 64f991fa7e..166053a24a 100644 --- a/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt @@ -1,9 +1,15 @@ classImplementsPrimitive.ts(3,20): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. classImplementsPrimitive.ts(4,21): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. classImplementsPrimitive.ts(5,21): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. +classImplementsPrimitive.ts(7,29): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. +classImplementsPrimitive.ts(8,29): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. +classImplementsPrimitive.ts(9,29): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. +classImplementsPrimitive.ts(11,31): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. +classImplementsPrimitive.ts(12,31): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. +classImplementsPrimitive.ts(13,31): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. -==== classImplementsPrimitive.ts (3 errors) ==== +==== classImplementsPrimitive.ts (9 errors) ==== // classes cannot implement primitives class C implements number { } @@ -17,10 +23,22 @@ classImplementsPrimitive.ts(5,21): error TS2864: A class cannot implement a prim !!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. const C4 = class implements number {} + ~~~~~~ +!!! error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. const C5 = class implements string {} + ~~~~~~ +!!! error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. const C6 = class implements boolean {} + ~~~~~~~ +!!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. const C7 = class A implements number { } + ~~~~~~ +!!! error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. const C8 = class B implements string { } + ~~~~~~ +!!! error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. const C9 = class C implements boolean { } + ~~~~~~~ +!!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt.diff deleted file mode 100644 index 20658b9fd3..0000000000 --- a/testdata/baselines/reference/submodule/compiler/classImplementsPrimitive.errors.txt.diff +++ /dev/null @@ -1,44 +0,0 @@ ---- old.classImplementsPrimitive.errors.txt -+++ new.classImplementsPrimitive.errors.txt -@@= skipped -0, +0 lines =@@ - classImplementsPrimitive.ts(3,20): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. - classImplementsPrimitive.ts(4,21): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. - classImplementsPrimitive.ts(5,21): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. --classImplementsPrimitive.ts(7,29): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. --classImplementsPrimitive.ts(8,29): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. --classImplementsPrimitive.ts(9,29): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. --classImplementsPrimitive.ts(11,31): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. --classImplementsPrimitive.ts(12,31): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. --classImplementsPrimitive.ts(13,31): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. -- -- --==== classImplementsPrimitive.ts (9 errors) ==== -+ -+ -+==== classImplementsPrimitive.ts (3 errors) ==== - // classes cannot implement primitives - - class C implements number { } -@@= skipped -22, +16 lines =@@ - !!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. - - const C4 = class implements number {} -- ~~~~~~ --!!! error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. - const C5 = class implements string {} -- ~~~~~~ --!!! error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. - const C6 = class implements boolean {} -- ~~~~~~~ --!!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. - - const C7 = class A implements number { } -- ~~~~~~ --!!! error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. - const C8 = class B implements string { } -- ~~~~~~ --!!! error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. - const C9 = class C implements boolean { } -- ~~~~~~~ --!!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt b/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt index c039a3048a..be4615ff35 100644 --- a/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt @@ -7,9 +7,15 @@ classExtendingPrimitive.ts(8,18): error TS2304: Cannot find name 'Null'. classExtendingPrimitive.ts(10,18): error TS2507: Type 'undefined' is not a constructor function type. classExtendingPrimitive.ts(11,18): error TS2552: Cannot find name 'Undefined'. Did you mean 'undefined'? classExtendingPrimitive.ts(14,18): error TS2507: Type 'typeof E' is not a constructor function type. +classExtendingPrimitive.ts(16,26): error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. +classExtendingPrimitive.ts(17,27): error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. +classExtendingPrimitive.ts(18,27): error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. +classExtendingPrimitive.ts(20,29): error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. +classExtendingPrimitive.ts(21,29): error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. +classExtendingPrimitive.ts(22,29): error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. -==== classExtendingPrimitive.ts (9 errors) ==== +==== classExtendingPrimitive.ts (15 errors) ==== // classes cannot extend primitives class C extends number { } @@ -44,10 +50,22 @@ classExtendingPrimitive.ts(14,18): error TS2507: Type 'typeof E' is not a constr !!! error TS2507: Type 'typeof E' is not a constructor function type. const C9 = class extends number { } + ~~~~~~ +!!! error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. const C10 = class extends string { } + ~~~~~~ +!!! error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. const C11 = class extends boolean { } + ~~~~~~~ +!!! error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. const C12 = class A extends number { } + ~~~~~~ +!!! error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. const C13 = class B extends string { } + ~~~~~~ +!!! error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. const C14 = class C extends boolean { } + ~~~~~~~ +!!! error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt.diff deleted file mode 100644 index 780d83592c..0000000000 --- a/testdata/baselines/reference/submodule/conformance/classExtendingPrimitive.errors.txt.diff +++ /dev/null @@ -1,44 +0,0 @@ ---- old.classExtendingPrimitive.errors.txt -+++ new.classExtendingPrimitive.errors.txt -@@= skipped -6, +6 lines =@@ - classExtendingPrimitive.ts(10,18): error TS2507: Type 'undefined' is not a constructor function type. - classExtendingPrimitive.ts(11,18): error TS2552: Cannot find name 'Undefined'. Did you mean 'undefined'? - classExtendingPrimitive.ts(14,18): error TS2507: Type 'typeof E' is not a constructor function type. --classExtendingPrimitive.ts(16,26): error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. --classExtendingPrimitive.ts(17,27): error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. --classExtendingPrimitive.ts(18,27): error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. --classExtendingPrimitive.ts(20,29): error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. --classExtendingPrimitive.ts(21,29): error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. --classExtendingPrimitive.ts(22,29): error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. -- -- --==== classExtendingPrimitive.ts (15 errors) ==== -+ -+ -+==== classExtendingPrimitive.ts (9 errors) ==== - // classes cannot extend primitives - - class C extends number { } -@@= skipped -43, +37 lines =@@ - !!! error TS2507: Type 'typeof E' is not a constructor function type. - - const C9 = class extends number { } -- ~~~~~~ --!!! error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. - const C10 = class extends string { } -- ~~~~~~ --!!! error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. - const C11 = class extends boolean { } -- ~~~~~~~ --!!! error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. - - const C12 = class A extends number { } -- ~~~~~~ --!!! error TS2863: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values. - const C13 = class B extends string { } -- ~~~~~~ --!!! error TS2863: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values. - const C14 = class C extends boolean { } -- ~~~~~~~ --!!! error TS2863: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values. - \ No newline at end of file