Skip to content

TS breaks with type alias as index signature #19146

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
theseyi opened this issue Oct 13, 2017 · 2 comments
Closed

TS breaks with type alias as index signature #19146

theseyi opened this issue Oct 13, 2017 · 2 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@theseyi
Copy link

theseyi commented Oct 13, 2017

TypeScript Version: 2.6.0-dev.201xxxxx

Code

enum StringEnum {
  Name = 'NAME',
  Email = 'EMAIL'
}

type EnumKeyed  = {
  [K in StringEnum]: string;
}

const obj: EnumKeyed = {
  NAME: 'aValue',
  EMAIL: 'bValue'
};

const array = Object.keys(obj) as Array<StringEnum>;
const result = array.map((key: StringEnum) => obj[key]);

Expected behavior:
result // ['aValue', 'bValue'];
Actual behavior:

TS throws:

Element implicitly has an 'any' type because type 'EnumKeyed' has no index signature.
const obj: EnumKeyed
@ahejlsberg
Copy link
Member

This looks like a duplicate of #16760 which is already fixed in 2.6. It doesn't reproduce with typescript@next. Are you sure you're on version 2.6?

@ahejlsberg ahejlsberg added the Needs More Info The issue still hasn't been fully clarified label Oct 13, 2017
@theseyi
Copy link
Author

theseyi commented Oct 13, 2017

Ah, apologies, was running on typescript@latest. This is fixed in @2.6.0-dev.20171013. Thanks so much @ahejlsberg

@theseyi theseyi closed this as completed Oct 13, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants