Typescript | Extends Error (uncaught Typeerror: This Is Not A X Object)
I create this class: class trueDate extends Date { constructor(date: string) { super(date) } getDay(): number { var day = super.getDay() return
Solution 1:
You should not (and can not in most if not all cases) inherit from native/primitive types. Extending primitive types is considered bad practice even in pure javascript (read the section 'Bad practice: Extension of native prototypes' here to learn a bit about why).
In this case it will not work because the Date class does not conform to how the inheritance works in typescript.
If you want to do something like this what you should do is a wrapper class or use something already existing, like moment.js for example.
Post a Comment for "Typescript | Extends Error (uncaught Typeerror: This Is Not A X Object)"