-
Notifications
You must be signed in to change notification settings - Fork 42
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
fix: overload faast() for specific providers #55
Conversation
Thanks for the pull request! I originally had overloads for To merge this we'll need to make some adjustments:
If this seems too daunting I'll take it on, just let me know. |
Also please do a pull before making any of the above changes, as I recently pushed a new version that makes significant changes. |
@acchou I've rebased, npm run build and improved the return type more specific.
Also the overloading three signature and the API docs are too heavy. What about another simple solution just changing the option type to union? export async function faast<M extends object>(
provider: Provider,
fmodule: M,
options?: AwsOptions | GoogleOptions | LocalOptions
): Promise<FaastModule<M>> {} |
I've tried that before and it resulted in some type errors in the testsuite, though that was a while ago and the testsuite has evolved. Let me play with this this afternoon and see what happens. |
The problem with a union type is that it leaves open the possibility of errors such as specifying "aws" as the provider, but giving Let's wait until api-documenter supports labels. In the meantime, the current typing for In the meantime, consider writing a wrapper function that's pretty much what export async function superfaast<M extends object>(
provider: "aws",
fmodule: M,
options?: AwsOptions
): Promise<AwsFaastModule<M>>;
export async function superfaast<M extends object>(
provider: "google",
fmodule: M,
options?: GoogleOptions
): Promise<GoogleFaastModule<M>>;
export async function superfaast<M extends object>(
provider: "local",
fmodule: M,
options?: LocalOptions
): Promise<LocalFaastModule<M>>;
export async function superfaast<M extends object>(
provider: Provider,
fmodule: M,
options?: CommonOptions
): Promise<FaastModule<M>>;
export async function superfaast<M extends object>(
provider: Provider,
fmodule: M,
options?: CommonOptions
): Promise<FaastModule<M>> {
switch (provider) {
case "aws":
return faastAws(fmodule, options);
case "google":
return faastGoogle(fmodule, options);
case "local":
return faastLocal(fmodule, options);
default:
throw new FaastError(`Unknown cloud provider option '${provider}'`);
}
} Or you can use the union type version for simplicity in your own code base, at the cost of possibly having runtime errors (likely caught by testing in practice). I've found that TypeScript doesn't always give good error message when using overloaded functions like
That's not very helpful, and likely to cause confusion. I like the provider-specific faast functions |
@acchou Good decision! Thank you for your investigation. |
Thank you for your awesome library!
I have a problem that an option would be a type error for a particular provider in
faast()
.This PR improve this with overloading.
While
faastAws
andfaastGoogle
is provided,faast()
is more convenient inif
conditional branches or switch cases.