You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use this plugin and this type doesn't seem to be very useful. Given that the useErrorHandler function takes a generic type for the context, I would expect the ErrorHandler type to also be generic instead of just using DefaultContext.
Additionally, depending on the phase, it seems like the type is actually different. The context value is passed to the error handler callback in the parse and validate phases, but in the execution phase it's passing a TypedExecutionArgs<ContextType>:
. So even though the type of context is Readonly<DefaultContext>, I need to look in context.contextValue (untyped) to get the same context value as the parse and validate phases.
And in the "context" phase, the context value passed to the error handler callback is a OnPluginInitEventPayload<ContextType>. I don't really understand why this is being passed to error handlers - it would make more sense to me if the context value was pulled from this callback instead:
Is your feature request related to a problem? Please describe.
The
context
property passed as the payload touseErrorHandler
callbacks is typed asReadonly<DefaultContext>
:envelop/packages/core/src/plugins/use-error-handler.ts
Line 11 in b7d0a94
I'm trying to use this plugin and this type doesn't seem to be very useful. Given that the
useErrorHandler
function takes a generic type for the context, I would expect theErrorHandler
type to also be generic instead of just usingDefaultContext
.Additionally, depending on the phase, it seems like the type is actually different. The context value is passed to the error handler callback in the parse and validate phases, but in the execution phase it's passing a
TypedExecutionArgs<ContextType>
:envelop/packages/core/src/plugins/use-error-handler.ts
Line 24 in b7d0a94
context
isReadonly<DefaultContext>
, I need to look incontext.contextValue
(untyped) to get the samecontext
value as the parse and validate phases.And in the "context" phase, the
context
value passed to the error handler callback is aOnPluginInitEventPayload<ContextType>
. I don't really understand why this is being passed to error handlers - it would make more sense to me if thecontext
value was pulled from this callback instead:envelop/packages/core/src/plugins/use-error-handler.ts
Line 48 in b7d0a94
But I'm not sure if it's intentional that the "onPluginInit" payload is being used instead.
Describe the solution you'd like
Make the
ErrorHandler
type a generic type with a tagged union:Describe alternatives you've considered
In my
useErrorHandler
plugin, explicitly cast the type ofcontext
based on the phase.Additional context
The text was updated successfully, but these errors were encountered: