Skip to content

'any'-typed json objects #1840

@dynst

Description

@dynst

Subissue of #1750

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

export interface Pubkey {
// type is one of the strings defined in pubkeyType
// I don't use a string literal union here as that makes trouble with json test data:
// https://github.com/cosmos/cosmjs/pull/44#pullrequestreview-353280504
readonly type: string;
readonly value: any;
}

/**
* We lost track on how the evidence structure actually looks like.
* This is any now and passed to the caller untouched.
*
* See also https://github.com/cosmos/cosmjs/issues/980.
*/
export type Evidence = any;

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.

public static decodeGenesis(response: JsonRpcSuccessResponse): responses.GenesisResponse {
return decodeGenesis(assertObject((response.result as GenesisResult).genesis));
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions