Add `isX` / `assertIsX` helpers for `Client` objects
- Ngôn ngữ chính
- TypeScript
- Star
- 695
- Fork
- 210
- Merge trung bình
- 21 giờ 33 phút
- Pull request đã merge (30 ngày)
- 90
Mô tả
## 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.
Hướng dẫn đóng góp
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- api
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100