Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit f938de6

Browse files
authored
Fix some type issues (#66)
* Fix some type errors * More fixup * fixup! More fixup * Remove needlessly complicated XOR type * fixup! Remove needlessly complicated XOR type
1 parent 8266456 commit f938de6

1 file changed

Lines changed: 40 additions & 26 deletions

File tree

src/index.d.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,77 @@
11

22
import { IEthereumRpcError } from 'eth-rpc-errors/@types'
33

4-
/** A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0". */
4+
/**
5+
* A String specifying the version of the JSON-RPC protocol.
6+
* MUST be exactly "2.0".
7+
*/
58
export type JsonRpcVersion = "2.0";
69

710
/** Method names that begin with the word rpc followed by a period character
811
* (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions
9-
* and MUST NOT be used for anything else. */
12+
* and MUST NOT be used for anything else.
13+
*/
1014
export type JsonRpcReservedMethod = string;
1115

12-
/** An identifier established by the Client that MUST contain a String, Number,
13-
* or NULL value if included. If it is not included it is assumed to be a
14-
* notification. The value SHOULD normally not be Null and Numbers SHOULD
15-
* NOT contain fractional parts [2] */
16+
/**
17+
* An identifier established by the Client that MUST contain a String, Number,
18+
* or NULL value if included. If it is not included it is assumed to be a
19+
* notification. The value SHOULD normally not be Null and Numbers SHOULD
20+
* NOT contain fractional parts.
21+
*/
1622
export type JsonRpcId = number | string | void;
1723

18-
interface JsonRpcError<T> extends IEthereumRpcError<T> {}
24+
export interface JsonRpcError<T> extends IEthereumRpcError<T> {}
1925

20-
interface JsonRpcRequest<T> {
26+
export interface JsonRpcRequest<T> {
2127
jsonrpc: JsonRpcVersion;
2228
method: string;
2329
id: JsonRpcId;
2430
params?: T;
2531
}
2632

27-
interface JsonRpcNotification<T> extends JsonRpcResponse<T> {
33+
export interface JsonRpcNotification<T> {
2834
jsonrpc: JsonRpcVersion;
35+
method: string,
2936
params?: T;
3037
}
3138

32-
interface JsonRpcResponse<T> {
33-
result?: any;
34-
error?: JsonRpcError<any>;
35-
jsonrpc: JsonRpcVersion;
36-
id: JsonRpcId;
39+
interface JsonRpcResponseBase {
40+
jsonrpc: JsonRpcVersion,
41+
id: JsonRpcId,
3742
}
3843

39-
interface JsonRpcSuccess<T> extends JsonRpcResponse<T> {
40-
result: any;
44+
export interface JsonRpcSuccess<T> extends JsonRpcResponseBase {
45+
result: T;
4146
}
4247

43-
interface JsonRpcFailure<T> extends JsonRpcResponse<T> {
44-
error: JsonRpcError<T>;
48+
export interface JsonRpcFailure<T> extends JsonRpcResponseBase {
49+
error: JsonRpcError<T>;
4550
}
4651

47-
type JsonRpcEngineEndCallback = (error?: JsonRpcError<any>) => void;
48-
type JsonRpcEngineNextCallback = (returnFlightCallback?: (done: () => void) => void) => void;
52+
export type JsonRpcResponse<T> = JsonRpcSuccess<T> | JsonRpcFailure<T>
4953

50-
interface JsonRpcMiddleware {
54+
export type JsonRpcEngineEndCallback = (error?: JsonRpcError<unknown>) => void;
55+
export type JsonRpcEngineNextCallback = (
56+
returnFlightCallback?: (done: () => void) => void,
57+
) => void;
58+
59+
export interface JsonRpcMiddleware {
5160
(
52-
req: JsonRpcRequest<any>,
53-
res: JsonRpcResponse<any>,
61+
req: JsonRpcRequest<unknown>,
62+
res: JsonRpcResponse<unknown>,
5463
next: JsonRpcEngineNextCallback,
5564
end: JsonRpcEngineEndCallback,
5665
) : void;
5766
}
5867

59-
interface JsonRpcEngine {
68+
export interface JsonRpcEngine {
6069
push: (middleware: JsonRpcMiddleware) => void;
61-
handle: (req: JsonRpcRequest<any>, callback: (error: JsonRpcError<any>, res: JsonRpcResponse<any>) => void) => void;
70+
handle: (
71+
req: JsonRpcRequest<unknown>,
72+
callback: (
73+
error: JsonRpcError<unknown>,
74+
res: JsonRpcResponse<unknown>,
75+
) => void,
76+
) => void;
6277
}
63-

0 commit comments

Comments
 (0)