Skip to content

Abstract Constructor is breaking on Class decorators #42370

@arciisine

Description

@arciisine

Bug Report

🔎 Search Terms

abstract constructor decorator

🕗 Version & Regression Information

4.2.0-dev.20210113

  • This is a bug tied to newly released functionality

⏯ Playground Link

Playground link with relevant code

💻 Code

type Class<T = any> = abstract new (...args: any[]) => T;

function Injectable() {
  return function <T>(target: Class<T>) { 
    return target;
  }
}


@Injectable()
class TestInjectable {

}

🙁 Actual behavior

Actual behavior is that TestInjectable is failing decoration with the error:

Unable to resolve signature of class decorator when called as an expression.
  Type 'Class<TestInjectable>' is not assignable to type 'typeof TestInjectable'.
    Cannot assign an abstract constructor type to a non-abstract constructor type.(1238)

🙂 Expected behavior

Given the blog post comment of:
Adding the abstract modifier to a construct signature signals that you can pass in abstract constructors. It doesn’t stop you from passing in other classes/constructor functions that are “concrete” – it really just signals that there’s no intent to run the constructor directly, so it’s safe to pass in either class type.

I'm expecting the Class alias to properly support both abstract and concrete classes, but that doesn't seem to be the case.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions