This is currently valid, legal TypeScript:
classContainer<A>{constructor(privatevalue: A){}act<BextendsA>(b: B){/*...*/}}But reversing the type bound in act doesn't work, i.e.
act<AextendsB>(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<BnarrowsA>(b: B){/*...*/}(meaning, B is a supertype of A).
Another possible alternative syntax:
act<Bwhere{AextendsB}>(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
This is currently valid, legal TypeScript:
But reversing the type bound in
actdoesn't work, i.e.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:
(meaning, B is a supertype of A).
Another possible alternative syntax:
Examples of implementations in other languages:
http://rustbyexample.com/generics/where.html
http://docs.scala-lang.org/tutorials/tour/lower-type-bounds.html