Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Typescript Newable Types
Construct signatures in interfaces are not implementable in classes; they're only for defining existing JS APIs that define a 'new'-able function. Here's an example involving interfaces new signatures that does work:
interface ComesFromString {
name: string;
interface StringConstructable {
new(n: string): ComesFromString;
class MadeFromString implements ComesFromString {
constructor (public name: string) {
console.log('ctor invoked');
function makeObj(n: StringConstructable) {
return new n('hello!');
This creates an actual constraint for what you can invoke makeObj with:
class Other implements ComesFromString {
constructor (public name: string, count: number) {
makeObj(Other); // Error! Other's constructor doesn't match StringConstructable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.