type FooOf<T> = Array<T> | { prop: T }
These are much more powerful than generics in languages like Java because they let you build an arbitrarily-tall tower of type abstractions. What I've found in practice is that at least when it comes to application code, these are rarely needed and cause more obfuscation than benefit.On the other hand, generic functions in TypeScript allow you to bind together the types of arguments and/or returned values:
function last<T>(arr: Array<T>): T {
return arr[arr.length - 1]
}
which I see as pretty essential. So my thinking is to allow the latter (as well as generic classes), but not the former (non-generic type aliases will still be available). There will also be some built-in generic types like promises (or some equivalent) and iterators.|> has special language-level status and works sort of like generics, but doesn't need to be implemented in terms of them (though it may end up that way just to simplify the compiler)