cosmjs icon indicating copy to clipboard operation
cosmjs copied to clipboard

'any'-typed json objects

Open dynst opened this issue 2 months ago • 0 comments

Subissue of #1750

There's a lot of any in the codebase, especially for JSON/protobuf stuff.

https://github.com/cosmos/cosmjs/blob/ca243f58727d5d7ee0f46fc562fb816baf4fca62/packages/amino/src/pubkeys.ts#L1-L7

https://github.com/cosmos/cosmjs/blob/ca243f58727d5d7ee0f46fc562fb816baf4fca62/packages/tendermint-rpc/src/tendermint34/responses.ts#L239-L245

And the parsing code looks weirdly structured and scattered around. Simple assertObject utility functions are defined 4 different times, copypasted around. Fields are checked piecemeal instead of a single pass validation to cast unknown or JsonValue to SpecificType - objects get casted as a class before actually confirming all mandatory fields are there.

https://github.com/cosmos/cosmjs/blob/ca243f58727d5d7ee0f46fc562fb816baf4fca62/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts#L881-L883

One of these could be useful:

https://www.npmjs.com/package/type-fest https://www.npmjs.com/package/json2typescript https://www.npmjs.com/package/typia https://www.npmjs.com/package/@total-typescript/ts-reset

dynst avatar Oct 09 '25 23:10 dynst