Commit f23a5ae
authored
chore: Improve
## Explanation
The `makeRequest` utility function is now easier to control the return
type of using a type parameter, while still defaulting to the correct
type by default most of the time.
The previous version of this utility function frequently required a type
cast to prevent the return type from being resolved to `never`. It was
technically possible to specify the return type with a type parameter,
but it was onerous because the exact input type would also be required
as the first parameter.
This was done to simplify a later PR (#7296) that enables a lint rule
preventing unnecessary type assertions. The rule ended up breaking these
tests because the cast impacted how the type was inferred in a way that
the rule didn't predict.
## References
Relates to #7296
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Refactors the `makeRequest` test util to a simpler generic signature
and updates tests to use explicit generics and local type aliases
instead of casts.
>
> - **Tests/Utils**:
> - **`makeRequest`**: Simplify to `<Request extends JsonRpcRequest =
JsonRpcRequest>(request: Partial<Request>) => Request`; remove dual
generics and `never`-prone casting.
> - **Tests**:
> - Replace casts with generic usage (e.g.,
`makeRequest<JsonRpcRequest>()`).
> - Introduce local alias `NumericIdRequest` and use
`makeRequest<NumericIdRequest>({...})` where needed.
> - Minor assertion updates to align with new typing (no runtime
behavior changes).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
554f7d8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->makeRequest test utility function (#7297)1 parent 7bb160f commit f23a5ae
File tree
2 files changed
+12
-14
lines changed- packages/json-rpc-engine
- src/v2
- tests
2 files changed
+12
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
811 | 811 | | |
812 | 812 | | |
813 | 813 | | |
814 | | - | |
815 | | - | |
816 | | - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
817 | 818 | | |
818 | 819 | | |
819 | 820 | | |
820 | 821 | | |
821 | 822 | | |
822 | 823 | | |
823 | 824 | | |
824 | | - | |
825 | | - | |
826 | | - | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
827 | 828 | | |
828 | 829 | | |
829 | 830 | | |
| |||
1210 | 1211 | | |
1211 | 1212 | | |
1212 | 1213 | | |
1213 | | - | |
| 1214 | + | |
1214 | 1215 | | |
1215 | 1216 | | |
1216 | 1217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 9 | + | |
| 10 | + | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| |||
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | | - | |
| 19 | + | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
| |||
0 commit comments