Skip to content

Unhelpful extra error that class prototype isn't assignable to superclass prototype #26138

Closed
@ghost

Description

TypeScript Version: 3.1.0-dev.20180801

Code

interface A {
    n: number;
}
declare var A: {
    prototype: A;
    new(): A;
};

class B extends A {
    n = "";
}

Expected behavior:

One error: Property 'n' in type 'B' is not assignable to the same property in base type 'A'.

Actual behavior:

Two errors:

src/a.ts:9:7 - error TS2417: Class static side 'typeof B' incorrectly extends base class static side '{ prototype: A; }'.
  Types of property 'prototype' are incompatible.
    Type 'B' is not assignable to type 'A'.
      Types of property 'n' are incompatible.
        Type 'string' is not assignable to type 'number'.

9 class B extends A {
        ~

src/a.ts:10:5 - error TS2416: Property 'n' in type 'B' is not assignable to the same property in base type 'A'.
  Type 'string' is not assignable to type 'number'.

10     n = "";

We could just omit static-side errors if instance-side errors exist.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions