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

asked Apr 19, 2017 at 12:37
8
  • see Why do 'some examples' and 'list of things' questions get closed? Commented Apr 19, 2017 at 12:45
  • 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. Commented Apr 19, 2017 at 12:50
  • 1
    @user108589: your EDIT github link pretty much summarizes the reasoning behind it. There you have your answer. Commented Apr 19, 2017 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. Commented Apr 19, 2017 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. Commented Apr 25, 2017 at 16:42

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.