react-promise-suspense icon indicating copy to clipboard operation
react-promise-suspense copied to clipboard

feat(lib): strongly typed usePromise

Open msereniti opened this issue 3 years ago • 4 comments

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
})()

msereniti avatar Jan 08 '22 19:01 msereniti

Hmm, @vigzmv and @Luxizzle, is that package still maintained or it's time to fork?

msereniti avatar Jan 11 '22 14:01 msereniti

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

vigzmv avatar Jan 11 '22 16:01 vigzmv

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

msereniti avatar Jan 19 '22 12:01 msereniti

Forked package https://www.npmjs.com/package/react-use-await

msereniti avatar Jan 20 '22 12:01 msereniti