1

I am looking for the equivalent of the following c# syntax for typescript

public abstract class PBaseHierarchical<T> : PBase where T : PBaseHierarchical<T>
    {
...
}

I only find the constraint "extends" which would be the following in typescript:

export abstract class PBaseHierarchical<T extends PBaseHierarchical<T>> extends PBase {
...
}

But from my understanding "extends" says that T should inherit from PBaseHierarchical. What I want is that T is of type PBaseHierarchical.

Thanks a lot for any help !

2
  • 1
    extends in type constraint is actually covers both: is of type PBaseHierarchical or "extends" PBaseHierarchical. Pretty much the same as where T : PBaseHierarchical in c# Commented Mar 2, 2019 at 7:53
  • Hi Alekey - thanks for your feedback ! If you post your answer I could mark it as a such. Commented Mar 2, 2019 at 13:41

1 Answer 1

1

extends in type constraint is actually covers both:

T is of type PBaseHierarchical or T "extends" PBaseHierarchical

Pretty much the same as where T : PBaseHierarchical in C#.

Also pay attention that types are compared structurally in Typescript.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.