Skip to content

Add Constructor<T> to lib.es5.d.ts #41656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
mlhaufe opened this issue Nov 23, 2020 · 2 comments
Closed
5 tasks done

Add Constructor<T> to lib.es5.d.ts #41656

mlhaufe opened this issue Nov 23, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@mlhaufe
Copy link

mlhaufe commented Nov 23, 2020

Search Terms

Constructor, utility type, lib.es5.d.ts

Suggestion

The following type should be added to lib.es5.d.ts:

type Constructor<T> = new (...args: any[]) => T

Use Cases

This is a common pattern used in mixins and other class oriented declarations:

This also complements the existing utility types:

image

Examples

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

function Tagged<T extends Constructor<{}>>(Base: T) {
    return class extends Base {
        _tag: string;
        constructor(...args: any[]) {
            super(...args);
            this._tag = "";
        }
    }
}

const TaggedPoint = Tagged(Point);

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@MartinJohns
Copy link
Contributor

Duplicate of #20256.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Nov 23, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@MartinJohns MartinJohns mentioned this issue May 28, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants