tern
tern copied to clipboard
Generics support
It would be nice if built-in stuff like arrays and new like Promises support could be generalized for other container types through generics which are supported in TypeScript/Flow/AtScript/etc. so we could define own containers with ease and without special inference magic for each separate case.
@marijnh Do you think that it's something easy to implement? If you could do it, we would have full type system support as in other mentioned annotation-based solutions (since union types are now implemented and only generics are missing). After it's implemented, I can update TypeScript definition converter to latest API and send PR.
I did half a 'generics' implementation for Promises (the -> Type[prop=...] syntax that is used for Promise.resolve). But this is a hack, and a more solid implementation would be good. Basically, I think we need a way to associate types with object types without stuffing them in properties (which is what my hack does), and a clean way to define functions that express relations between such types. Speaking of which, array type handling is also currently rather crude, and it would be nice if a generics system could clean it up.
This would be great to have, but I have not thought much about how to design it yet.
I think best would be to adapt googles definition: https://github.com/google/closure-compiler/wiki/Generic-Types