Skip to content

NewableFunction not working as intended #44337

Closed
@rajmondx

Description

@rajmondx

There is little info about NewableFunction except for the meeting notes in #27102 and the pr #27028.

As far as I understand the comments there, a NewableFunction should be "callable" with new Foo(...), right? Or do we have to stick with apply(...)/call(...)?

Example:

class Foo {}

function doSomething(clazz: NewableFunction) {
  new clazz();
  // This expression is not constructable.
  //   Type 'NewableFunction' has no construct signatures
}



doSomething(Foo); // passes but would fail with "normal functions" aka. CallableFunction

Question about workaround:

If NewableFunction works as desired should we stick with new Function.prototype.bind.call(clazz, undefined); or should we define our own "ConstructableFunction" (a lot of people suggest this and even angular did it):

eg.

export interface ConstructableFunction extends NewableFunction {
  new(...args: any[]): any
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions