Add `isX` / `assertIsX` helpers for `Client` objects
- Dominant language
- TypeScript
- Stars
- 695
- Forks
- 210
- Avg merge
- 21h 33m
- Merged PRs (30d)
- 90
Description
## Motivation
See https://github.com/anza-xyz/kit-plugins/pull/361#discussion_r3764610661
Many plugins include code along the lines of:
```ts
if (!client.planTransaction || !client.planTransactions) {
throw new Error('some error message')
}
```
Other objects in Kit, like `TransactionMessage`, have a rich API of `isX` and `assertIsX` helpers to check their runtime properties + type narrow.
We should add similar helpers for clients.
## Example use case
```ts
assertIsClientWithPlanningFunctions(client)
```
## Details
It would probably make sense to use the `ClientWithX` boundaries, so test for both `planTransaction` and `planTransactions` together for instance.
These would be added to the `plugin-interfaces` package alongside these types
Would also make sense to add to the wallet plugin (which doesn't have its Client type in Kit, so this is a change in kit-plugins)
Would throw `SolanaError` for the `assertIsX` helpers, removing a non-typed error path from most plugins.
Contributor guide
Research direction
Start in the plugin-interfaces package where the ClientWithX types are defined, then inspect the analogous isX and assertIsX helpers on TransactionMessage. Review the wallet plugin's Client type as well. Done means the relevant ClientWithX boundaries have runtime checks, type-narrowing assertions throw SolanaError, and tests cover the helpers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100