-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 top-level types of send
function
#4145
Changes from 5 commits
d5ea716
c17b83e
84fd2b8
30c2e28
3102013
eda6f09
94b0a0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,25 +7,31 @@ export type Init = typeof init; | |||||||||||||||
|
||||||||||||||||
export function send<K extends keyof Handlers>( | ||||||||||||||||
name: K, | ||||||||||||||||
args?: Parameters<Handlers[K]>[0], | ||||||||||||||||
options?: { catchErrors: true }, | ||||||||||||||||
): ReturnType< | ||||||||||||||||
| { data: Handlers[K] } | ||||||||||||||||
| { error: { type: 'APIError' | 'InternalError'; message: string } } | ||||||||||||||||
args: Parameters<Handlers[K]>[0], | ||||||||||||||||
options: { catchErrors: true }, | ||||||||||||||||
): Promise< | ||||||||||||||||
| { data: Awaited<ReturnType<Handlers[K]>>; error: undefined } | ||||||||||||||||
| { | ||||||||||||||||
data: undefined; | ||||||||||||||||
error: { type: 'APIError' | 'InternalError'; message: string }; | ||||||||||||||||
} | ||||||||||||||||
>; | ||||||||||||||||
export function send<K extends keyof Handlers>( | ||||||||||||||||
name: K, | ||||||||||||||||
args?: Parameters<Handlers[K]>[0], | ||||||||||||||||
options?: { catchErrors?: boolean }, | ||||||||||||||||
): ReturnType<Handlers[K]>; | ||||||||||||||||
): Promise<Awaited<ReturnType<Handlers[K]>>>; | ||||||||||||||||
export type Send = typeof send; | ||||||||||||||||
|
||||||||||||||||
export function sendCatch<K extends keyof Handlers>( | ||||||||||||||||
name: K, | ||||||||||||||||
args?: Parameters<Handlers[K]>[0], | ||||||||||||||||
): ReturnType< | ||||||||||||||||
| { data: Handlers[K] } | ||||||||||||||||
| { error: { type: 'APIError' | 'InternalError'; message: string } } | ||||||||||||||||
): Promise< | ||||||||||||||||
| { data: Awaited<ReturnType<Handlers[K]>>; error: undefined } | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remove this I get const { data, error } = await sendCatch('gocardless-get-banks', country); I don't see any other way to keep the ability to destructure like this, any ideas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. In that case we should probably just merge those two properties and make them both optional. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I kind of like being able to assert that |
||||||||||||||||
| { | ||||||||||||||||
data: undefined; | ||||||||||||||||
error: { type: 'APIError' | 'InternalError'; message: string }; | ||||||||||||||||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
Comment on lines
+31
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as above |
||||||||||||||||
>; | ||||||||||||||||
export type SendCatch = typeof sendCatch; | ||||||||||||||||
|
||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [jfdoming] | ||
--- | ||
|
||
Fix types of `send` function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update error handling to match the updated 'send' function behavior.
With the changes to the
send
function, errors are now thrown instead of being returned whencatchErrors
is not set totrue
. The current code checks for anerror
property in the response, which may no longer be valid. To maintain the existing error handling, consider usingsendCatch
or passing{ catchErrors: true }
as an options parameter.Apply one of the following solutions to update the code:
Option 1: Use
sendCatch
functionOption 2: Use
send
withcatchErrors: true
option