microsoft / microsoft/TypeScript

Generators/Async Generators with TReturn type argument which extends undefined have a return method with a non-optional argument in 3.6.2

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

@rbuckton đang làm issue này rồi.

Từ ngày 16/9/2019.

Needs Investigation
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ả

TypeScript Version: 3.6.2

Search Terms:
generator iterator return argument optional required

Code

function *gen(): Generator<number, number | undefined> {
  yield 1;
  return 2;
}

gen().return();

Expected behavior:
The argument passed to the return method should be optional. Not sure if this is possible with typescript.

Actual behavior:

file.ts(6,7): error TS2554: Expected 1 arguments, but got 0.
6 gen().return();
        ~~~~~~~~

  typescript/lib/lib.es2015.generator.d.ts:26:12
    26     return(value: TReturn): IteratorResult<T, TReturn>;
                  ~~~~~~~~~~~~~~
    An argument for 'value' was not provided.

Playground Link:

Playground is not available for 3.6.2

Related Issues:
#30790 Strongly typed iterator PR.
#32682 Other (async) iterator usability issues.
#33239 Trouble implementing async iterator interface in 3.6.2
#33241 Unable to use done property of IteratorResult to narrow types in typescript 3.6.2

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.

Đánh giá

Issue này chưa được đánh giá.

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.