You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
andreibancioiu
changed the title
Add type guards around important functions
Add runtime type guards around important functions
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:
Impact on existing code: we should strive to have only fixing changes - and avoid breaking changes on this topic.
The text was updated successfully, but these errors were encountered: