microsoft / microsoft/TypeScript

Strict Reflect.apply Reflect.construct and Function.prototype.apply/call/bind

Đang mở
#33,889 6 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc các khai báo hiện tại và các bài kiểm tra kiểm tra kiểu liên quan đến Reflect.apply, Reflect.construct và Function.prototype.apply/call/bind. So sánh chúng với các kiểu trả về dự kiến trong issue và xác minh rằng các ví dụ được liệt kê suy ra string và ClassA thay vì any.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript
Lĩnh vực
compilers
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.