microsoft / microsoft/TypeScript
Type Inference in for... in combined with typeof
未关闭
还没有人认领这个 Issue。
Help Wanted
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 2.1.4
The following code gives an error in TS 2.1:
It's not really nice code, but I think it should work never the less :)
for (var a in this) {
if (typeof this[a] === "function" && !ko.isObservable(this[a]))
this[a] = this[a].bind(this);
}
Expected behavior:
I would expect this[a] to be typed as this[keyof this] & Function:
for (var a in this) {
if (typeof this[a] === "function" && !ko.isObservable(this[a]))
this[a] =( <this[keyof this] & Function> this[a]).bind(this);
}
Actual behavior:
It gives an error, as of TS 2.1, it worked in TS 2.0 (because mapped types did not exist, this[a] was typed as any)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用提供的 for...in 和 typeof 示例重现 TypeScript 2.1 错误,然后将其行为与 TypeScript 2.0 进行比较。跟踪 this[a] 通过 for...in narrowing 路径时的类型推断;完成的标准是该示例无需显式 cast 即可通过类型检查,同时保留预期的函数 narrowing。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100