-
Notifications
You must be signed in to change notification settings - Fork 9
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
Return type for functionRunner #43
Comments
The return type of the function runner is not a It is If you see the docs, it can be an HTTP response, or a void function, etc. I'm not aware of any time the function would (or should) return the context. I'm not really clear on what the linting error is there, perhaps because the screen shots don't show enough context, but I can't tell why or where you'd be wanting to assert the type is a |
OK - right, my confusion here is that the So if your underlying function is not returning a value, you'll get the context back, but if it does return something then you get that back. So we can't just declare the return type as a |
Ah ok interesting. In that case would allowing passing a generic type for the return of the underlying function be a possible option? Perhaps having it default to export async function functionRunner<T = unkown>(
azFunction: AzureFunction,
bindingDefinitions: BindingDefinition[] | string = [],
bindingData: Record<string, Binding> = {},
augmentContext?: AugmentContextCallback
): Promise<T> { ... |
It could be generic, or maybe even using the return type of |
OK - there doesn't seem to be a way to infer the return type, which would be a bit nicer than forcing the use of a generic. I've added it as a generic in #44, but I would prefer to add a conditional return type if we could evaluate if the azure function was a void function or not... |
Yeh that'd be ideal. I'm not sure it's possible though because of the |
Well, if a function is declared to return |
OK - I think I've managed to get it working so it will infer the return type successfully. Do you think you could install the branch that #44 is based on and see if that resolves your problems? |
It may just be that the way our team has written our functions is a little niche and perhaps not quite the intended approach. e.g. our functions will always have a return type of export const httpTrigger: AzureFunction = async (context): Promise<void> => {
context.res = {
status: 200,
body: {
status: 'Healthy',
},
};
}; |
When I check it locally the typings seem to be resolving even for your example signature, I've even turned on the So it doesn't like the default |
Yeh looks like it works perfectly if I change my function to not use the // triggers eslint rule in test, functionRunner return type any
export const httpTrigger: AzureFunction = async (context): Promise<void> => {}
// doesn't trigger eslint rule, functionRunner return type Context
export const httpTrigger = async (context: Context): Promise<void> => {} I'm happy with this solution if you are! |
Currently the
functionRunner
has a return type ofPromise<any>
.This results in a few
typescript-eslint
errors:Assigning result :
Trying to type with
Promise<Context>
:For now we've got around this by adding an overload to our project:
It'd be ideal if the type were narrowed in the package itself. Is there a reason it's currently
any
? IsContext
a sufficient type?The text was updated successfully, but these errors were encountered: