react-promise-suspense
react-promise-suspense copied to clipboard
feat(lib): strongly typed usePromise
Pull request name describes PR enough
Working types proof:
const fakeResult: any = null;
const usePromise = <Args extends any[], Result extends any>(promise: (...inputs: Args) => Promise<Result>, inputs: Args, lifespan?: number = 0): Result => {
return fakeResult
};
(async () => {
const someDataSource = async(query: string, page: number): Promise<string[]> => fakeResult
const query: string = 'x';
const page: number = 0;
const fetchedData = await usePromise(someDataSource, [query, page]);
fetchedData.join() // <-- typed as array
const stringifiedPage: string = '0';
await usePromise(someDataSource, [query, stringifiedPage]); // <-- trhows an error
})()
Hmm, @vigzmv and @Luxizzle, is that package still maintained or it's time to fork?
Thanks for the support @phytonmk. Could you update to provide default []
value to inputs
.
This is an experimental package and won't get any updates other than bug fixes, please feel free to fork or create your own for your use case. Thanks
This is an experimental package and won't get any updates other than bug fixes, please feel free to fork or create your own for your use case. Thanks
I have found this package both very useful and uncompleted. So I am going to fork it with strong typings, issues resolving, packages updating and CI/CD
Forked package https://www.npmjs.com/package/react-use-await