Skip to content

Port TS PR 60490 #1255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { }
Expand All @@ -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.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Expand Down Expand Up @@ -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.

This file was deleted.