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

Autocomplete for String Union Types #9512

Closed
Meligy opened this issue Jul 5, 2016 · 2 comments
Closed

Autocomplete for String Union Types #9512

Meligy opened this issue Jul 5, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Meligy
Copy link

Meligy commented Jul 5, 2016

Let's say I have the following type:

 type Cars = 'Ferrari' | 'Volvo' | 'Porsche';

It will be awesome if I can treat it like an enum, meaning I can write Cars. and get intellisense for Ferari, Volve, and Porsche.

Today, you do not get that.

You can have funky workarounds to make the number based enum become a string

Like this (runnable sample):

enum Cars {
    Ferrari = <any> "Ferrari",
    Volvo = <any> "Volvo",
    Porsche = <any> "Porsche"
}

But that's hacking, even though it opens the question why not make this a core feature.

Or, you can use namespaces, like (runnable sample):

type Cars = 'Ferrari' | 'Volvo' | 'Porsche';
namespace Cars {
    export const Ferrari : Cars = "Ferrari";
    export const Volvo : Cars = "Volvo";
    export const Porsche : Cars = "Porsche";
}

But obviously, this way you can get into errors, with both the type and namespace potentially going out of sync due to human error.

Ideally, the very first line should in itself allow you to have autocomplete, similar to what enum does. Or alternatively of course support string enum types.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 5, 2016

But that's hacking, even though it opens the question why not make this a core feature.

that is the plan. we need to come up with a detailed proposal. we have talked about this in the past in #5740 and #5943.

the feature is tracked by #1206

For auto completions in IDE's this already coverd by #8428

image

@mhegazy
Copy link
Contributor

mhegazy commented Jul 5, 2016

unless this is more to this request that allowing string enums, i would close this in favor of #1206.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jul 5, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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

3 participants