Skip to content

String literal union types are validated, but values are not suggested by IDEs #12891

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

Closed
grantbowering opened this issue Dec 13, 2016 · 1 comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@grantbowering
Copy link

In the 3 IDEs I've tried (VS2015u3, VS2017RC, and VSCode 1.7.2), string literal union type values are detected and underlined in real time if invalid, and the error message lists values that would be valid, but the IDE won't help you type those values or suggest anything.

TypeScript Version: 2.1.4

Code

// A *self-contained* demonstration of the problem follows...
import { Reducer } from 'redux';

export interface CounterState {
    count: number;
}

interface IncrementCountAction { type: 'INCREMENT_COUNT' }
interface DecrementCountAction { type: 'DECREMENT_COUNT' }

export type KnownAction = IncrementCountAction | DecrementCountAction;

export const reducer: Reducer<CounterState> = (state: CounterState, action: KnownAction) => {
    switch (action.type) {
        case 'INCREMENT_CO':
            return { count: state.count + 1 };
        case 'DECREMENT_COUNT':
            return { count: state.count - 1 };
        default:
            const exhaustiveCheck: never = action;
    }

    return state || { count: 0 };
};

The value is detected as an error in all IDEs, and the tooltip in all IDEs indicates what values (or the first several until trailing off, if there are many) are valid:

tsautocomplete1

Expected behavior:

Auto-completion suggestions should include, and be limited to, the same two possible string values that are indicated in the error.

Actual behavior:

tsautocomplete2

VS2015u3 and VS2017RC provide no suggestions. VSCode technically does provide the suggestion given the sample above, but only because it appears as a literal in the same file and VSCode always does that; if you move the reducer function to a separate file, VSCode will not have a suggestion either.

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor labels Dec 13, 2016
@RyanCavanaugh RyanCavanaugh added the Fixed A PR has been merged for this issue label Aug 13, 2018
@RyanCavanaugh
Copy link
Member

This should be fixed in almost all cases; please log a bug with complete repro steps if you find a case where it isn't working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants