Skip to content

Commit cac6b2c

Browse files
committed
more friendly type constraint
1 parent 263bc2c commit cac6b2c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/types.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { JSONRPCErrorInterface } from './dto/errors.ts'
22

3+
/**
4+
* This can be used for constrain of type that can be converted to json
5+
*/
36
export type JSONRPCValue = PrimitiveValue | StructuredValue
47

58
export type PrimitiveValue = string | number | boolean | null
@@ -19,22 +22,20 @@ export type ArrayValue = Array<JSONRPCValue>
1922
*
2023
* If method throws a value that is not `JSONRPCError`, it will be treated as `JSONRPCInternalError`
2124
*
22-
* Note that client is allowed to send no params, meaning that params can also be `undefined`
25+
* Note that client is allowed to send no params, meaning that params can also be `undefined`,
26+
* server may also send result `undefined`
2327
*/
2428
export interface JSONRPCMethods {
25-
[method: string]: JSONRPCMethod
29+
// deno-lint-ignore no-explicit-any
30+
[method: string]: JSONRPCMethod<any, any>
2631
}
2732

2833
/**
2934
* Represent any json rpc method, any detailed method should extend it
30-
*
31-
* Note that for a request, `params` MUST be `JSONRPCValue`,
32-
* however here `params` is `any` (just for simplicity)
3335
*/
34-
export type JSONRPCMethod = (
35-
// deno-lint-ignore no-explicit-any
36-
params: any, //! client may send any params to server
37-
) => Promise<JSONRPCValue> | JSONRPCValue
36+
export type JSONRPCMethod<Params, Result> = (
37+
params: Params,
38+
) => Promise<Result> | Result
3839

3940
export type WithOptionalJSONRPCVersion<T extends object> =
4041
& Omit<T, 'jsonrpc'>

0 commit comments

Comments
 (0)