Skip to content

fix(55500): Incorrect error reported when using class extends null an… #57349

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 src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44656,8 +44656,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (!checkTypeAssignableTo(typeWithThis, baseWithThis, /*errorNode*/ undefined)) {
issueMemberSpecificError(node, typeWithThis, baseWithThis, Diagnostics.Class_0_incorrectly_extends_base_class_1);
}
else {
// Report static side error only when instance type is assignable
else if (staticBaseType !== nullWideningType) {
// Report static side error only when instance type is assignable and base type is not null
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
}
if (baseConstructorType.flags & TypeFlags.TypeVariable) {
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/classExtendsNull2.errors.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to increase the coverage you could test this with strictNullChecks on and off (currently it's only tested with strictNullChecks: true)

Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
classExtendsNull2.ts(5,7): error TS2417: Class static side 'typeof C' incorrectly extends base class static side 'null'.
classExtendsNull2.ts(7,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'.


==== classExtendsNull2.ts (2 errors) ====
==== classExtendsNull2.ts (1 errors) ====
// https://github.com/microsoft/TypeScript/issues/55499

interface Base {}

class C extends null {
~
!!! error TS2417: Class static side 'typeof C' incorrectly extends base class static side 'null'.
constructor() {
super();
~~~~~~~
Expand Down