Skip to content

Commit

Permalink
feat: JSON RPC types should properly narrow union types
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Nov 29, 2024
1 parent 5b7938d commit 5b4aec9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ type JSONRPCRequestMetadata = Partial<{
type JSONRPCRequestParams<
T extends JSONObject = JSONObject,
M extends JSONObject = JSONObject,
> = {
metadata?: JSONObject &
JSONRPCRequestMetadata &
Omit<T['metadata'] & M, keyof JSONRPCRequestMetadata>;
} & Omit<T, 'metadata'>;
> = T & {
metadata?: JSONRPCResponseMetadata &
M &
(T extends { metadata: infer U } ? U : JSONObject) &
JSONObject;
};

type JSONRPCResponseMetadata = Partial<{
timeout: number | null;
Expand All @@ -150,11 +151,12 @@ type JSONRPCResponseMetadata = Partial<{
type JSONRPCResponseResult<
T extends JSONObject = JSONObject,
M extends JSONObject = JSONObject,
> = {
metadata?: JSONObject &
JSONRPCResponseMetadata &
Omit<T['metadata'] & M, keyof JSONRPCResponseMetadata>;
} & Omit<T, 'metadata'>;
> = T & {
metadata?: JSONRPCResponseMetadata &
M &
(T extends { metadata: infer U } ? U : JSONObject) &
JSONObject;
};

/**
* This is a JSON RPC error object, it encodes the error data for the JSONRPCResponseFailed object.
Expand Down

0 comments on commit 5b4aec9

Please sign in to comment.