microsoft / microsoft/TypeScript
Use any instead of unknown for AsyncGenerator optional .next parameter
@rbuckton 已经在做这个了。
开始于 2019年9月17日。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。