javascript - 可迭代和异步可迭代对象的流注释?
问题描述
我有一个函数foo
可以返回一个可以迭代的对象:
const foo = () => ({
[Symbol.iterator]: function * () {
yield * [ 1, 2, 3 ];
},
});
for (const x of foo()) {
console.log(x);
}
// 1
// 2
// 3
现在我想foo
用 Flow 类型定义进行注释。但是这些看起来像什么?
另外,async
版本bar
呢?
const bar = () => ({
[Symbol.asyncIterator]: async function * () {
yield * [ 1, 2, 3 ];
},
});
for await (const x of bar()) {
console.log(x);
}
解决方案
推荐阅读
- python - 是否可以在 Python 3 中获取类型化类属性的 DocString?
- c# - VS gitignore 问题
- linux - 在 RHEL - 4.7 中安装 perl-LWP-Protocol-https
- ruby - 在 ruby 编程中是否对已注册的电子邮件 ID 进行任何验证检查
- c# - 在 Windows Form .Net 中使用 FtpWebRequest 下载 FTP
- c - 发送带有 MSG_ZEROCOPY 的 udp 消息时,什么会导致返回 SO_EE_CODE_ZEROCOPY_COPIED?
- c# - 如何使用 web api 确保 ssrs 安全
- csvhelper - 如何将 csv 中的引号传递给 CsvHelper 写入的文件
- sql - 通过 executeQuery 运行更新查询
- multithreading - 如何在 C++ 中 printf() std::this_thread::get_id()?