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.
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.
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.
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
left a comment
There was a problem hiding this comment.
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.
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 |
I missed a couple of errors in #66. While fixing them, I decided to add types for all exports as well.