An utility function that makes MobX flow type-safe
npm install to-flow-generator-function

The toFlowGeneratorFunction is a utility function that converts a promise-returning function into a generator-returning function. It is designed to enable the usage of type-safe yield statements inside MobX flow wrapper.
- fn: The promise-returning function to be converted into a generator-returning function.
``typescript
import { flow } from 'mobx';
import { toFlowGeneratorFunction, type FlowGenerator } from 'to-flow-generator-function';
interface UserData {
id: number;
name: string;
age: number;
}
const fetchUserName = (id: number): Promise
const fetchUserAge = (id: number): Promise
function* fetchUserData(id: number): FlowGenerator
const name = yield* toFlowGeneratorFunction(fetchUserName)(id);
// Here, name has the type string.age
const age = yield* toFlowGeneratorFunction(fetchUserAge)(id);
// Here, has the type number.
return {
id,
name,
age,
};
}
const userId = 3;
const userData = await flow(fetchUserData)(userId);
// Here, useData has the type UserData.``
More examples in toFlowGeneratorFunction.spec.ts