3 ms·
Yeah, this is something I had hoped for as well. Mobx-state-tree [1] also makes use of generators for asynchronous tasks and typescript's inability to infer typ
by lf-non 7y ago
Yeah, this is something I had hoped for as well. Mobx-state-tree [1] also makes use of generators for asynchronous tasks and typescript's inability to infer types of values returned from a yield is a pain.
But fortunately, atleast in this particular case the usage semantics are really close to async/await so I have had success using a babel macro [2][3] to transform async functions to generators which restores type-safety. This is of-course a hack but has proven to work fairly well in practice.
[1] https://github.com/mobxjs/mobx-state-tree https://github.com/mobxjs/mobx-state-tree
[2] https://github.com/kentcdodds/babel-plugin-macros https://github.com/kentcdodds/babel-plugin-macros
[3] https://github.com/ts-delight/async-to-generator.macro https://github.com/ts-delight/async-to-generator.macro