Question involving generics +enumerations ?

Topics: General, Language Specification
Jul 30, 2014 at 1:30 AM
First post please be kind... I recently have been tinkering with TypesScript generics and I am trying to understand something about the way generics work (or didn't in my case), I have placed the broken generic and the working version of the class in the same shared playground ( ), hopefully it survives the trip otherwise none of this will make sense.

As you can see, the difference between the broken and working version is that I simply changed references to the enumeration into references to the generic parameter. You will notice that on the TypeScript side of the playground there are three minor problems that show up where the generic parameter is used. I thought it was a constraint problem, but after a few attempts and thanks to looking at the generated Javascript I decided I needed to find a forum and ask a question to more seasoned/expert typescript programmers.

What can I do that will coax the compiler into passing the generic types into the construction function much the same way as it does for the 'super' type? Looking at the output also explained why I was having with issues trying to use (CRTP) in a different context, what am I missing here is this possible without resorting to some crude manual edits?

-- BPT
Jul 30, 2014 at 5:35 PM

When cross-posting to StackOverflow, please include a link so people don't duplicate their effort.
Jul 30, 2014 at 5:41 PM
sorry about that
Jul 30, 2014 at 11:51 PM
I have a follow-up question with generics and enumerations, in the form of a comment*. The problem has moved to when I specify the constraint and pass different enumerations to the generic. Here is a link to the stackoverflow topic, my last comment includes an updated shared playground url with the new problem being demonstrated at bottom three lines.

Also for the members of the language team, kudos to you all - I am finding adopting Javascript into my solution arsenal is much more palatable with TypeScript, the ability to work so well with existing Javascript is a godsend.

I also have a suggestion about constraint nomenclature, implements seems more natural but is not accepted? extends makes plenty of sense as well but implies (to me) a much stricter set of demands on the type provided?

(*This probably violates half a dozen best practices with posting something on stackoverflow)