feat(context): force interceptor functions to return a value#5357
Merged
raymondfeng merged 1 commit intomasterfrom May 7, 2020
Merged
feat(context): force interceptor functions to return a value#5357raymondfeng merged 1 commit intomasterfrom
raymondfeng merged 1 commit intomasterfrom
Conversation
The `NonVoid` return type prohibits an interceptor function from having void return type. This is important that an interceptor should either return the value from downstream interceptors or a value from its own.
38a2976 to
2aaf5c6
Compare
deepakrkris
approved these changes
May 7, 2020
Contributor
deepakrkris
left a comment
There was a problem hiding this comment.
LGTM, an explicit negative test case could be helpful
Contributor
Author
|
Unfortunately a negative case will fail to compile. |
Member
TypeScript 3.9 is adding I am not sure if we are using 3.9 yet, there is an older (but less strict) alternative |
bajtos
reviewed
May 7, 2020
|
|
||
| function logInterceptor(ctx: InvocationContext, next: Next) {} | ||
| function logInterceptor(ctx: InvocationContext, next: Next) { | ||
| return undefined; |
Member
There was a problem hiding this comment.
I find this redundant and a bit silly, because in JavaScript, functions return undefined when there is no return statement. I guess the extra verbosity is worth the stronger type safety your change provides.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
NonVoidreturn type prohibits an interceptor function from havingvoid return type. This is important that an interceptor should either
return the value from downstream interceptors or a value from its own.
For example, the code will fail to compile.
Related to #5339
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈