Skip to content

Add runtime type guards around important functions #485

@andreibancioiu

Description

@andreibancioiu

For example, add runtime type guards on the Transaction constructor. Throw errors if type constraints aren't satisfied. This might not be in tone with TypeScript's philosophy, but it's important in practice, to aid debugging.

Today we had a quite long debugging session around a snippet such as:

// Receive a plain transaction object from a source
const input: any = { ... }

// Incorrect, with bugs, but no compile time & runtime errors
const transaction = new Transaction(input);

// Correct (but suboptimal design):
const transaction = Transaction.fromPlainObject(input);

Impact on existing code: we should strive to have only fixing changes - and avoid breaking changes on this topic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions