Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Type Alias #1959

Closed
RamIdeas opened this issue Feb 6, 2015 · 1 comment
Closed

Generic Type Alias #1959

RamIdeas opened this issue Feb 6, 2015 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@RamIdeas
Copy link

RamIdeas commented Feb 6, 2015

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:

  1. reduces my flexibility to use whatever type I want (without having to create more interfaces)
  2. reduces readability as Visual Studio's colourisation won't colour string, number and boolean in blue, and
  3. 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 {}
// ...
@danquirk
Copy link
Member

danquirk commented Feb 6, 2015

See #1616

@danquirk danquirk closed this as completed Feb 6, 2015
@danquirk danquirk added the Duplicate An existing issue was already created label Feb 6, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants