Skip to content

Value of string literal type as property name. #6080

Closed
@vilicvane

Description

@vilicvane

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

Metadata

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