Skip to content

Value of string literal type as property name. #6080

Closed
@vilicvane

Description

For example:

type Method = 'get' | 'post';

let app = {
    get() { },
    post() { },
    foo() { },
    bar: 123
};

let methodA = 'get';
let handlerA = app[methodA]; // typeof handlerA === () => void

let methodB: Method;
let handlerB = app[methodB]; // typeof handlerB === () => void

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Domain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions