microsoft / microsoft/TypeScript
Strict Reflect.apply Reflect.construct and Function.prototype.apply/call/bind
未关闭
还没有人认领这个 Issue。
Awaiting More Feedback
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
Search Terms
Reflect.apply
Reflect.construct
Function.prototype.apply
Function.prototype.call
Function.prototype.bind
Suggestion
These functions should not return any.
Related:
https://github.com/microsoft/TypeScript/issues/212
https://github.com/microsoft/TypeScript/pull/27028
Use Cases
function getString() {
return 'string'
}
class ClassA {}
Reflect.apply(getString, null, []) // expected string but got any
Reflect.construct(ClassA, []) // expected ClassA but got any
Function.prototype.apply.call(getString, undefined) // expected string but got any
Function.prototype.call.call(getString, undefined) // expected string but got any
Function.prototype.bind.call(getString, undefined)() // expected string but got any
Examples
Reflect:
// old
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
// new
function apply<T>(target: (...args: any) => T, thisArgument: any, argumentsList: ArrayLike<any>): T;
// old
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: any): any;
// new
function construct<T>(target: new (...args: any) => T, argumentsList: ArrayLike<any>, newTarget?: any): T;
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
👆 Add a new compiler option - This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 Reflect.apply、Reflect.construct 和 Function.prototype.apply/call/bind 的当前声明及相关类型检查测试。将它们与 issue 中预期的返回类型进行比较,并验证所列示例推断出的类型是 string 和 ClassA,而不是 any。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100