Skip to content

Instantly share code, notes, and snippets.

@chaance
Created March 3, 2021 16:03
Show Gist options
  • Save chaance/9fde8d0be7c70c2b0d77d3a6faa3d900 to your computer and use it in GitHub Desktop.
Save chaance/9fde8d0be7c70c2b0d77d3a6faa3d900 to your computer and use it in GitHub Desktop.
constructor-type-question.ts
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