microsoft / microsoft/TypeScript

map through enum

未关闭
#28,565 6 条评论 13 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Needs Proposal Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

TypeScript Version: 3.1.6

Search Terms: enum

Code

enum ABC {
  A = 'A',
  B = 'B',
  C = 'C',
}
// No Error
for (const key in ABC) {
  console.log(ABC[key]);
}
// Error: Element implicitly has an 'any' type because index expression is not of type 'number'
Object.keys(ABC).map(key => console.log(ABC[key]));

Expected behavior:
Object.keys, values, entries on enum ABC infer type of ABC's key and value.
Actual behavior:
Cannot get inferred type.

Shouldn't type of key from enum be 'A' | 'B' | 'C'?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 TypeScript 3.1.6 重现 issue 中的 enum 和 Object.keys 示例,然后比较 for-in 和 Object.keys 情况下推断出的类型。当 Object.keys、values 和 entries 在没有 implicit-any 错误的情况下提供预期的 enum 键类型和值类型时,工作即完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。