3

I have been struggling to understand the reasons why typescript developers choose the way they implemented inheritance.

What I would expect from any language supporting inheritance is these order of work:

  1. The derived class initialized properties are initialized
  2. The base class initialized properties are initialized
  3. The base class constructor runs
  4. The derived class constructor runs

What apparently happens:

  1. The base class initialized properties are initialized
  2. The base class constructor runs
  3. The derived class initialized properties are initialized
  4. The derived class constructor runs

I don't yet understand what kinds of benefits come from implementing this kind of inheritance

My question boiling down to this:

What kinds of projects makes this implementation of inheritance perfect for?

EDIT: relevant link to discussion: https://github.com/Microsoft/TypeScript/issues/1617

  • 3
    I don't understand the close vote, it looks both like a legitimate and even interesting question to me. ...*maybe* the reason is related to some JavaScript constraints / compatibility issues. – dagnelies Apr 19 '17 at 12:50
  • 1
    @user108589: your EDIT github link pretty much summarizes the reasoning behind it. There you have your answer. – dagnelies Apr 19 '17 at 12:56
  • 3
    @dagnelies: the question asks for a list of projects (or more precisely, for a list of kinds of projects). List questions are off-topic. The interestingness of the question is irrelevant. There are lots of things that are of interest, but not on-topic. – Jörg W Mittag Apr 19 '17 at 13:02
  • 2
    It is more than simply following the protocol of another language. The order of initialization ensures that pre-conditions and invariants in the base class are satisfied before the derived class begins execution. This is important for proving correctness. – Frank Hileman Apr 25 '17 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.