Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): strongly typed usePromise #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

msereniti
Copy link

@msereniti msereniti commented Jan 8, 2022

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
Copy link
Author

msereniti commented Jan 11, 2022

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

@vigzmv
Copy link
Owner

vigzmv commented Jan 11, 2022

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

@msereniti
Copy link
Author

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 msereniti mentioned this pull request Jan 19, 2022
@msereniti
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants