microsoft / microsoft/TypeScript

Object.assign({}) seems to always return a type any

未关闭
#29,348 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Domain: lib.d.ts
主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

描述

TypeScript Version: 3.3.0-dev.20190110

Search Terms: Object.assign

Code

function foo(): {foo: string} {
    return Object.assign({});
}

Interestingly the code:

function bar(): {bar: string} {
    return Object.assign({}, {bar: 1});
}

does report the expected error

Expected behavior: TypeScript should report an error because the type returned by return Object.assign({}); does not mach {foo: string} but instead the type any is assumed.

Actual behavior: No error is shown

Playground Link: https://www.typescriptlang.org/play/index.html#src=function%20foo()%3A%20%7Bfoo%3A%20string%7D%20%7B%0D%0A%20%20%20%20return%20Object.assign(%7B%7D)%3B%0D%0A%7D%0D%0A

Related Issues: no

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先,使用 issue 中的 TypeScript 版本和当前的 nightly build,在链接的 TypeScript Playground 中重现报告的 Object.assign 示例。跟踪编译器如何为 Object.assign({}) 推断类型,并添加一个回归测试,验证当返回值不满足 {foo: string} 时会被拒绝。

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

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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