Description
Missing Type Verification for smartContract
Client
Description
Currently, there are no compile-time or run-time checks to verify that smartContract
is a client for the MINER_TO_PEERID contract. The method smartContract.getPeerData
may not exist.
With the current implementation, when the caller supplies a wrong smart contract client, the code fails with the following error:
❯ node
Welcome to Node.js v22.13.0.
Type ".help" for more information.
> {}.getPeerData(123)
Uncaught TypeError: {}.getPeerData is not a function
Impact
This is primarily a developer-experience issue. While the error message is somewhat descriptive, adding proper type checking could improve the developer experience by catching this issue earlier (at compile time) or providing more specific error messages (at runtime).
Suggested Solution
Consider implementing one or both of the following:
-
Type checking: Add TypeScript interfaces or type definitions for the expected contract client, ensuring compile-time validation.
-
Runtime validation: Add runtime validation to check if the provided
smartContract
has the required methods before attempting to use them, with a more descriptive error message.
Original Discussion
This issue was originally flagged by @bajtos in a PR review comment:
#2 (comment)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status