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

Completion should prefer literal types in union types #13614

Closed
notoriousb1t opened this issue Jan 21, 2017 · 3 comments
Closed

Completion should prefer literal types in union types #13614

notoriousb1t opened this issue Jan 21, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@notoriousb1t
Copy link

TypeScript Version: 2.2.0-dev.20170120

Code

interface ICssProperties {
    display: 'inline-block' | string
}

const className: ICssProperties = {
    display: ''
}

Expected behavior:
The auto completion list shows 'inline-block' followed by general string suggestions

Actual behavior:
The auto completion list shows general string suggestions none of which are 'inline-block;

@ghost
Copy link

ghost commented Jan 21, 2017

Duplicate of #12687.

@notoriousb1t
Copy link
Author

@andy-ms, from your comment in the other thread, it sounds like someone chose to make a regression in tooling in exchange for a compiler optimization. For a language like TypeScript where one of its largest features is good tooling, I think this is a mistake.

The TypeStyle project leverages literal types to provide good auto-completion for css property values. A lot of properties have exact keywords for which type ahead support is great. However, a lot of these can also take units like 3px which can't be described to the type system, so we have to fallback to a string.

Here is an issue recently brought by a developer using TypeStyle: typestyle/typestyle#104

What would it take to restore this behavior?

@rozzzly
Copy link

rozzzly commented Jan 22, 2017

I agree with @notoriousb1t . This is a feature I really want; there's tons of instances where it can make writing quality code quicker—one of the things about TypeScript that makes the DX so great. Granted, the spec does denote that in such cases the union would get widened to string, yet, those suggestions are still highly relevant. Can't there be some convenient deviation from the what the type checker derives.

So all we see when querying the type checker for the type of x is string. So, this can't be fixed.
— @andy-ms

That's such a cop-out man. I'm not familiar with the internals of the type checker, but surely some metadata could be supplied to the completion provider alongside the results from the type checker.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jan 23, 2017
@mhegazy mhegazy closed this as completed Apr 21, 2017
@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