Skip to content

NewableFunction not working as intended #44337

Closed

Description

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
}

Activity

  1. rajmondx commented on May 30, 2021

    @rajmondx
    Author

    Ended up using something like this:

    interface ConstructableFunctionTyped<T> extends NewableFunction {
      new(...args: any[]): T;
    }
    
    export type ConstructableFunction = ConstructableFunctionTyped<any>;
    export type Class = ConstructableFunctionTyped<Object>;
  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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