-
-
Notifications
You must be signed in to change notification settings - Fork 62
Add missing types, fix remaining faulty ones #67
Conversation
export type JsonRpcEngineNextCallback = ( | ||
returnFlightCallback?: (done: () => void) => void, | ||
returnHandlerCallback?: ReturnHandlerCallback, |
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.
This was one of the errors. You can actually pass errors to the return handler callbacks in order to cause the JSON-RPC request to return an error.
src/index.d.ts
Outdated
type ScaffoldMiddlewareHandler = JsonRpcMiddleware | ( | ||
boolean | number | string | Record<string, unknown> | unknown[] | null | undefined | ||
) |
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.
This one is a little iffy. Really, I want to type it like: if it's a function, then it has to extend JsonRpcMiddleware
, otherwise it can be anything.
OTOH, even that is perhaps a bit too permissive, since the values should probably be serializable 🤔
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.
Maybe something like this? I think what you have is correct but just throwing out another possibility to look into.
type Serializable = boolean | number | string | Record<string, unknown> | unknown[] | null | undefined;
type ScaffoldMiddlewareHandler<T> = T extends Function ? JsonRpcMiddleware : Serializable;
export interface createScaffoldMiddleware<T> {
(handlers: {[methodName: string]: ScaffoldMiddlewareHandler<T>}): JsonRpcMiddleware;
}
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.
LGTM, added a thing you could tinker with but its non blocking
src/index.d.ts
Outdated
type ScaffoldMiddlewareHandler = JsonRpcMiddleware | ( | ||
boolean | number | string | Record<string, unknown> | unknown[] | null | undefined | ||
) |
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.
Maybe something like this? I think what you have is correct but just throwing out another possibility to look into.
type Serializable = boolean | number | string | Record<string, unknown> | unknown[] | null | undefined;
type ScaffoldMiddlewareHandler<T> = T extends Function ? JsonRpcMiddleware : Serializable;
export interface createScaffoldMiddleware<T> {
(handlers: {[methodName: string]: ScaffoldMiddlewareHandler<T>}): JsonRpcMiddleware;
}
@brad-decker, that's a really neat suggestion! I accepted it here: 51f7f9a |
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.
Woot LGTM
I missed a couple of errors in #66. While fixing them, I decided to add types for all exports as well.