-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Typescript conversion of send-metadata.js #23738
base: develop
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
eb10177
to
47ae366
Compare
Builds ready [47ae366]
Page Load Metrics (836 ± 470 ms)
Bundle size diffs
|
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
This PR has been automatically marked as stale because it has not had recent activity in the last 60 days. It will be closed in 14 days. Thank you for your contributions. |
This PR was closed because there has been no follow up activity in the last 14 days. Thank you for your contributions. |
2601cfa
to
88e900b
Compare
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request |
Builds ready [5ed20fc]
Page Load Metrics (572 ± 417 ms)
Bundle size diffs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the implicit any
typing of the Infer
type (and downstream types InferWithParameters
, JsonRpcRequest
etc.) has not been resolved.
Perhaps we could look into upgrading @metamask/utils
in extension to 8.5.0
+, and migrating to @metamask/superstruct
? It looks like a number of different versions for utils and superstruct are being used in extension.
Leaving a blocking review for now. I don't believe we should be shipping implicit anys into the codebase under any circumstance. Restoring the JavaScript file would be preferable as it would at least correctly set expectations.
The implicit any
seems to be an issue with local dev environment. So long as tsc
is passing in CI, we should be good to proceed (See: #23504 (comment))
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implicit any
typing needs to be resolved (see https://github.com/MetaMask/metamask-extension/pull/23738/files#r1743724867).
I was able to fix the implicit All resulting type errors are resolved with these changes: diff --git a/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts b/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
index a6b4cec847..5bec59b57a 100644
--- a/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
+++ b/app/scripts/lib/rpc-method-middleware/handlers/send-metadata.ts
@@ -3,12 +3,8 @@ import {
JsonRpcEngineEndCallback,
JsonRpcEngineNextCallback,
} from 'json-rpc-engine';
-import {
- Json,
- JsonRpcParams,
- JsonRpcRequest,
- PendingJsonRpcResponse,
-} from '@metamask/utils';
+import type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';
+import { isObject } from '@metamask/utils';
import {
PermissionSubjectMetadata,
SubjectType,
@@ -21,7 +17,7 @@ type SubjectMetadataToAdd = PermissionSubjectMetadata & {
subjectType?: SubjectType | null;
extensionId?: string | null;
iconUrl?: string | null;
-} & Record<string, Json>;
+};
type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void;
@@ -30,9 +26,11 @@ type SendMetadataOptions = {
subjectType: SubjectType;
};
-type SendMetadataConstraint<Params extends JsonRpcParams = JsonRpcParams> = {
+type SendMetadataConstraint<
+ Params extends SubjectMetadataToAdd = SubjectMetadataToAdd,
+> = {
implementation: (
- req: JsonRpcRequest<Params>,
+ req: JsonRpcRequest<Params> & { origin: string },
res: PendingJsonRpcResponse<true>,
_next: JsonRpcEngineNextCallback,
end: JsonRpcEngineEndCallback,
@@ -64,15 +62,17 @@ export default sendMetadata;
* metadata, bound to the requesting origin.
* @param options.subjectType - The type of the requesting origin / subject.
*/
-function sendMetadataHandler<Params extends JsonRpcParams = JsonRpcParams>(
- req: JsonRpcRequest<Params>,
+function sendMetadataHandler<
+ Params extends SubjectMetadataToAdd = SubjectMetadataToAdd,
+>(
+ req: JsonRpcRequest<Params> & { origin: string },
res: PendingJsonRpcResponse<true>,
_next: JsonRpcEngineNextCallback,
end: JsonRpcEngineEndCallback,
{ addSubjectMetadata, subjectType }: SendMetadataOptions,
): void {
const { origin, params } = req;
- if (params && typeof params === 'object' && !Array.isArray(params)) {
+ if (isObject(params)) {
const { icon = null, name = null, ...remainingParams } = params;
addSubjectMetadata({
These are valid errors we should be seeing, but they're being suppressed by the implicit |
## **Description** Major version bump for `@metamask/utils`. - Fixes critical issue of all `@metamask/utils` and `superstruct` types downstream of `Infer` being typed as implicit `any`, suppressing valid type errors. - See #23738 (comment) - Causes large number of type error regressions which are resolved here: #26143 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26551?quickstart=1) ## **Related issues** - [x] Blocked by #26143 ## **Manual testing steps** ## **Screenshots/Recordings** ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
5ed20fc
to
68cb2b4
Compare
Builds ready [68cb2b4]
Page Load Metrics (1860 ± 111 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Quality Gate failedFailed conditions |
Builds ready [d6f2439]
Page Load Metrics (1876 ± 127 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
d6f2439
to
e0a1047
Compare
Part of #23014
Fixes #23472
Converting the level 6 dependency file
app/scripts/lib/rpc-method-middleware/handlers/send-metadata.js
to typescript for contributing tometamask-controller.js
.Description
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist