Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime type guards around important functions #485

Open
andreibancioiu opened this issue Sep 26, 2024 · 0 comments
Open

Add runtime type guards around important functions #485

andreibancioiu opened this issue Sep 26, 2024 · 0 comments
Labels
task Task

Comments

@andreibancioiu
Copy link
Contributor

andreibancioiu commented Sep 26, 2024

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.

@andreibancioiu andreibancioiu changed the title Add type guards around important functions Add runtime type guards around important functions Sep 26, 2024
@andreibancioiu andreibancioiu added the task Task label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Task
Projects
None yet
Development

No branches or pull requests

1 participant