Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Generic type mismatch with Readonly<T> #18094

Copy link
Copy link
@dpogue

Description

@dpogue
Issue body actions

This feels like #16985 in a slightly different form.
/cc @ahejlsberg

TypeScript Version: 2.5.1, but probably broken since 2.4.1

Code

interface MyInterface {
  something: number;
}

class MyClass<T extends MyInterface> {
  doIt(data : Readonly<T>) {}
}

interface II2 extends MyInterface {
  foo: string;
}

class MySubClass extends MyClass<II2> {}

function fn(arg: typeof MyClass) {};

fn(MySubClass);

Expected behavior:
No compilation error.

Actual behavior:

error TS2345: Argument of type 'typeof MySubClass' is not assignable to parameter of type 'typeof MyClass'.
  Type 'MySubClass' is not assignable to type 'MyClass<T>'.
    Types of property 'doIt' are incompatible.
      Type '(data: Readonly<II2>) => void' is not assignable to type '(data: Readonly<T>) => void'.
        Types of parameters 'data' and 'data' are incompatible.
          Type 'Readonly<T>' is not assignable to type 'Readonly<II2>'.
            Property 'foo' is missing in type 'Readonly<T>'.
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.