Last active
May 15, 2021 19:23
-
-
Save isometriq/9fa036fafc0b2332f17bef9630852efc to your computer and use it in GitHub Desktop.
Typescript implicit super constructor for inherited class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Artist { | |
constructor( | |
public name: string, | |
public age: number, | |
public style: string, | |
public location: string, | |
) { | |
// base logic | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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