Closed
Description
This is currently valid, legal TypeScript:
class Container<A> {
constructor(private value: A) {}
act<B extends A>(b: B) { /*...*/ }
}
But reversing the type bound in act
doesn't work, i.e.
act<A extends B>(b: B) { /*...*/ }
is not valid.
Ideally, the class's generic parameter can be used in any position.
Alternatively, we could support lower type bounds through a new keyword, narrows:
act<B narrows A>(b: B) { /*...*/ }
(meaning, B is a supertype of A).
Another possible alternative syntax:
act<B where { A extends B }>(b: B) { /*...*/ }
Examples of implementations in other languages:
http://rustbyexample.com/generics/where.html
http://docs.scala-lang.org/tutorials/tour/lower-type-bounds.html
Metadata
Metadata
Assignees
Labels
No labels