0

Can somebody explain why the following isn't allowed in Typescript?

interface Base<T> {
}

interface SomeInterface<First, Second extends Base<First>> {
}

For some reason I do not understand, it is not possible to refer to type First in Base<First>.

The error is: Constraint of type parameter cannot reference any type parameter from the same parameter list.

1
  • If an answer was provided, you should really not just read & ignore it, but provide feedback and, if it answered the question fully, mark it as accepted. Commented Mar 23, 2015 at 17:28

1 Answer 1

2

According to the wiki on breaking changes for 0.9.7, this was introduced to reduce overhead:

Instead, use constraint arguments that are not in the same argument list, make constraints non-generic, or simply pass 'any' as the parameter to the constraint.

Reason: The added overhead in terms of type-checking, error-reporting, and design complexity did not add enough additional expressiveness to make it worthwhile for 1.0. We may revisit this in future versions of TypeScript.

Your usecase is exactly one of the two mentioned ones in the documentation there.

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.