microsoft / microsoft/TypeScript
Use any instead of unknown for AsyncGenerator optional .next parameter
@rbuckton đang làm issue này rồi.
Từ ngày 17/9/2019.
- 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ả
TypeScript Version: 3.6.2
Search Terms:
async generator, AsyncGenerator, optional .next
Code
The following causes a type error:
async function* sequence(iterable: AsyncIterable<number>): AsyncGenerator<number> {
yield 12;
try {
// Type error: Cannot delegate iteration to value because the 'next' method of its iterator expects type 'undefined', but the containing generator will always send 'unknown'.
yield* iterable;
} finally {
console.log('Cleanup!');
}
}
Expected behavior:
I would've expected it to be a non-type error.
Problem:
The primary annoyance with this is that I'd like to use AsyncGenerator<T> just for specifying that .return() can be used without non-null assertions (.return!()) for early cleanup but AsyncGenerator<T> results in AsyncGenerator<T, any, unknown> so AsyncIterable<T> can't be delegated to.
Proposed solution:
Change interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> to interface AsyncGenerator<T = unknown, TReturn = any, TNext = any.
This won't break anything as any is assignable to anything, and I doubt it'll be problematic as those using AsyncGenerator<T> (or AsyncGenerator<T, S>) presumably do not care about the .next parameter.
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.
Đánh giá
Issue này chưa được đánh giá.