Skip to content

Instantly share code, notes, and snippets.

@nicu-chiciuc
Last active October 20, 2019 12:49
Show Gist options
  • Save nicu-chiciuc/4027039a419f146e235454cbface2ebf to your computer and use it in GitHub Desktop.
Save nicu-chiciuc/4027039a419f146e235454cbface2ebf to your computer and use it in GitHub Desktop.
type UnpackPromise<T> = T extends Promise<infer U> ? U : T;
const callAsync = <K extends keyof KnownMethods = keyof KnownMethods>(
methodName: K,
arg: FirstArgument<KnownMethods[K]>
) =>
new Promise<UnpackPromise<ReturnType<KnownMethods[K]>>>((resolve, reject) =>
(Meteor.call as any)(methodName, arg, (error: Error, result: any) => {
if (error) {
reject(error);
} else {
resolve(result);
}
})
);
export default callAsync;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment