Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonRpcRequest allows non-JSON values #129

Closed
legobeat opened this issue Aug 24, 2023 · 0 comments · Fixed by #130
Closed

JsonRpcRequest allows non-JSON values #129

legobeat opened this issue Aug 24, 2023 · 0 comments · Fixed by #130

Comments

@legobeat
Copy link
Contributor

legobeat commented Aug 24, 2023

The resulting type of JsonRpcRequest:

export declare const JsonRpcRequestStruct: Struct<{
    id: string | number | null;
    method: string;
    jsonrpc: "2.0";
    params?: Json[] | Record<string, Json> | undefined;
}, {
    id: Struct<string | number | null, null>;
    jsonrpc: Struct<"2.0", "2.0">;
    method: Struct<string, null>;
    params: Struct<Json[] | Record<string, Json> | undefined, null>;
}>;


export declare type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> = InferWithParams<typeof JsonRpcRequestStruct, Params>;

This allows explicit undefined value for params, which is invalid JSON since undefined is not a valid JSON value. params?: Json[] | Record<string, Json> | undefined; should be params?: Json[] | Record<string, Json>;.

It seems like superstruct-derived optional always get a | undefined, which makes the resolution less obvious to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant