Skip to content

Generic return value of a mixin constructor #22431

Closed
@Xenya0815

Description

@Xenya0815

TypeScript Version: 2.8.0-dev.20180308

Code

interface Instance {
  foo: number;
}

interface Constructor<I extends Instance> {
  new(): I;
}

function MixIn<T extends Instance>(Base: Constructor<T>) {
  return class extends Base {
    
  }
}

Expected behavior:
That my MixIn accepts that construct so that I can define a extended interface T with properties which are available at a instance of the MixIn class.

Actual behavior:

error TS2509: Base constructor return type 'T' is not a class or interface type.

It works when I remove the generic type at the function MixIn (like function MixIn(Base: Constructor<Instance>)) .

Related Issues:
I found old issues like #8853 or #4890
Because that I thought it should work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions