Closed
Description
What is the reason for disallowing generic type aliases?
I know you can use an empty interface definition to achieve the same thing, such as:
interface KO<T> extends KnockoutObservable<T> {}
But the limitation with interfaces is you can't use primitives or union types.
I want to be able to write:
type KnockoutWrapped<T> = T | KnockoutObservable<T>;
// or: type KW<T> = T | KO<T>;
// ensure I call ko.unwrap to get value
But my only option right now is:
type KnockoutWrappedString = string | KnockoutObservable<string>;
type KnockoutWrappedNumber = number | KnockoutObservable<number>;
type KnockoutWrappedBoolean = boolean | KnockoutObservable<boolean>;
// ...
// or:
type KWString = string | KO<string>;
type KWNumber = number | KO<number>;
type KWBoolean = boolean | KO<boolean>;
Which:
- reduces my flexibility to use whatever type I want (without having to create more interfaces)
- reduces readability as Visual Studio's colourisation won't colour
string
,number
andboolean
in blue, and - quite frankly, makes me type more -- reminiscent of back before typescript included generics and I was writing:
interface KOString extends KnockoutObservableString {}
interface KONumber extends KnockoutObservableNumber {}
interface KOBoolean extends KnockoutObservableBoolean {}
// ...