microsoft / microsoft/TypeScript

Iterator Helpers: `return` method typing is weaker than ideal

Đang mở
#60,176 0 bình luận 1 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.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

⚙ Compilation target

ESNext

⚙ Library

esnext.iterator.d.ts

Missing / Incorrect Definition

The return method always exists on iterators returned by Iterator.from (iter in below code) and iterators returned by Iterator Helpers methods (iter2 in below code).

However, it is defined as optional in the current definition. This could be improved.

Please note that you can't just add a non-optional return method definition to the IteratorObject type -- iterators returned by builtin methods other than Iterator Helpers don't have that method (iter3).

P.S. if you are interested in a motivating example, I don't have one. Sorry 🤪

Sample Code
const iter = Iterator.from({ next() { return { done: false, value: 0 }} });

iter.return(); // should not error

const iter2 = iter.map(x => x);

iter2.return(); // should not error

const iter3 = [].values();

iter3.return(); // Note: this error IS correct

Playground

Documentation Link

https://tc39.es/proposal-iterator-helpers/

Spec states that below objects always have the return method:

  • %WrapForValidIteratorPrototype%
  • %IteratorHelperPrototype%

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 trong esnext.iterator.d.ts và kiểm tra các định nghĩa IteratorObject, Iterator.from và Iterator Helpers đối chiếu với mã mẫu. Xác minh hành vi mong đợi theo đặc tả Iterator Helpers được liên kết: Iterator.from và kết quả của các helper phải cho phép return(), trong khi [].values() vẫn phải tiếp tục từ chối nó. Hoàn tất khi các khai báo phân biệt được các trường hợp này mà không tạo ra lỗi cho iter3.

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
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
58/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.