Created
March 3, 2021 16:03
-
-
Save chaance/9fde8d0be7c70c2b0d77d3a6faa3d900 to your computer and use it in GitHub Desktop.
constructor-type-question.ts
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 Base { | |
static booted() { | |
console.log(false); | |
} | |
constructor() { | |
// This is a valid way to call a static method | |
// from a non-static method AFAICT. | |
// Anyone know why TS can't infer more from | |
// from the type of this.constructor? | |
// | |
// ERROR: Property 'booted' does not exist on | |
// type 'Function' | |
this.constructor.booted(); | |
} | |
} | |
class SubClass extends Base { | |
static booted() { | |
console.log(true); | |
} | |
} | |
let c = new SubClass() // logs `true` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment