Last active
October 20, 2019 12:49
-
-
Save nicu-chiciuc/4027039a419f146e235454cbface2ebf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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