Skip to content

Instantly share code, notes, and snippets.

@isometriq
Last active May 15, 2021 19:23
Show Gist options
  • Save isometriq/9fa036fafc0b2332f17bef9630852efc to your computer and use it in GitHub Desktop.
Save isometriq/9fa036fafc0b2332f17bef9630852efc to your computer and use it in GitHub Desktop.
Typescript implicit super constructor for inherited class
class Artist {
constructor(
public name: string,
public age: number,
public style: string,
public location: string,
) {
// base logic
}
}
// Would be nice a new `super` keyword
// that is like `constructor` but with
// an implicit inherited signature
class StreetArtist extends Artist {
super(
// Automatic prepended signature based on inherited class
// name: string,
// age: number,
// style: string,
// location: string,
// Extended signature
public medium: string,
public famous: boolean,
public arrested: boolean,
) {
// base logic, already executed implicitly
// extended logic
}
}
new Artist("picasso", 139, "cubism", "spain");
new StreetArtist("anonymous", 30, "percussion", "new-york", "drums", false, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment