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

Value of string literal type as property name. #6080

Closed
vilicvane opened this issue Dec 12, 2015 · 6 comments
Closed

Value of string literal type as property name. #6080

vilicvane opened this issue Dec 12, 2015 · 6 comments
Labels
Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@vilicvane
Copy link
Contributor

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
@saschanaz
Copy link
Contributor

See also #394 (or #1295?)

@vilicvane
Copy link
Contributor Author

@saschanaz Thanks for the reference. So basically now we may have memberof operator return a string literal type, that's interesting. Hopefully somebody would take that PR.

@DanielRosenwasser
Copy link
Member

I know @weswigham has brought this up, though I'm not sure if there's an existing issue for it.

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Dec 14, 2015
@DanielRosenwasser DanielRosenwasser added the Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined label Jan 25, 2016
@masaeedu
Copy link
Contributor

@vilic What does the snippet demonstrate?

@vilicvane
Copy link
Contributor Author

@masaeedu Hmm, I think it's about finding a common type among several properties (within the range of string literals union).

@DanielRosenwasser DanielRosenwasser added the Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. label Jan 27, 2016
@RyanCavanaugh RyanCavanaugh removed Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Jan 27, 2016
@DanielRosenwasser DanielRosenwasser added the Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined label Feb 1, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Nov 2, 2016

This should be addressed by the new indexing support for literal types in #11929

@mhegazy mhegazy closed this as completed Nov 2, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed In Discussion Not yet reached consensus labels Nov 2, 2016
@mhegazy mhegazy added this to the TypeScript 2.1.2 milestone Nov 2, 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
Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants