microsoft / microsoft/TypeScript
Iterator Helpers: `return` method typing is weaker than ideal
Chưa có ai nhận issue này.
- 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
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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