diff --git a/src/json.ts b/src/json.ts index 9f10ef71d..3bd142f75 100644 --- a/src/json.ts +++ b/src/json.ts @@ -13,7 +13,6 @@ import { nullable, number, object, - omit, optional, record, string, @@ -178,7 +177,7 @@ export type JsonRpcError = OptionalField< >; export const JsonRpcParamsStruct: Struct, null> = - optional(union([record(string(), JsonStruct), array(JsonStruct)])) as any; + union([record(string(), JsonStruct), array(JsonStruct)]); export type JsonRpcParams = Json[] | Record; @@ -186,20 +185,15 @@ export const JsonRpcRequestStruct = object({ id: JsonRpcIdStruct, jsonrpc: JsonRpcVersionStruct, method: string(), - params: JsonRpcParamsStruct, + params: optional(JsonRpcParamsStruct), }); export type InferWithParams< Type extends Struct, Params extends JsonRpcParams, -> = Omit, 'params'> & - (keyof Params extends undefined - ? { - params?: Params; - } - : { - params: Params; - }); +> = Omit, 'params'> & { + params?: Exclude; +}; /** * A JSON-RPC request object. @@ -207,7 +201,11 @@ export type InferWithParams< export type JsonRpcRequest = InferWithParams; -export const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']); +export const JsonRpcNotificationStruct = object({ + jsonrpc: JsonRpcVersionStruct, + method: string(), + params: optional(JsonRpcParamsStruct), +}); /** * A JSON-RPC notification object.