【问题标题】:How to export generator function in TypeScript?如何在 TypeScript 中导出生成器函数?
【发布时间】:2018-04-27 03:43:34
【问题描述】:

我在 JS 中有这个例子:

export function* mySaga () {
    yield takeEvery('USER_FETCH_REQUESTED', fetchUser);
}

我可以在 TypeScript 中将其重写为箭头函数吗,如下所示?

export const mySaga* = () {
    yield takeEvery('USER_FETCH_REQUESTED', fetchUser);
}

【问题讨论】:

    标签: javascript typescript generator


    【解决方案1】:

    请记住,TypeScript 主要尝试成为 JavaScript 加类型(但早期采用新功能)。有is no arrow form of a generator function。但是,Brendan Eich 和 Domenic Denicola 是supposed to be working on one

    (TypeScript 规范只为其Generator Functions 部分提供了一个占位符[该链接将与部分编号 相关联],并且the issue 与在TypeScript 中实现生成器无关,@ 987654325@ 提到了箭头形式。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2021-12-28
      • 2020-07-26
      • 2020-03-11
      • 2013-02-28
      • 1970-01-01
      • 2020-04-21
      相关资源
      最近更新 更多