Skip to content

Remove explicit any usage and enforce stricter lint/type rules#3831

Open
MontrealAI wants to merge 1 commit into
mainfrom
codex/remove-any-and-type-casting-usages
Open

Remove explicit any usage and enforce stricter lint/type rules#3831
MontrealAI wants to merge 1 commit into
mainfrom
codex/remove-any-and-type-casting-usages

Conversation

@MontrealAI

Copy link
Copy Markdown
Owner

Motivation

  • Eliminate widespread use of any casts and unsafe type assertions to improve runtime safety and enable stronger static checks.
  • Introduce explicit unknown handling and typed guards so data parsed from external sources is validated before use.
  • Harden lint and TypeScript configs to prevent regression by surfacing any usage and unsafe catch typings.
  • Keep existing behavior unchanged while making the codebase safer and easier to reason about.

Description

  • Replaced any and as any casts with unknown-aware code, typed guards (isRecord) and safe conversion helpers across orchestrator, validator, console, onebox, arena and shared modules (examples: apps/orchestrator/*, apps/validator/*, apps/console/*, services/arena/*, shared/*).
  • Tightened runtime parsing and Zod schemas to use z.unknown() instead of z.any() for input records and payloads (files: packages/onebox-sdk/src/types.ts, packages/onebox-orchestrator/src/ics/schema.ts, packages/orchestrator/src/ics.ts, services/arena/src/validators.ts).
  • Added small helper types and declarations: isRecord guards, toStringValue, typed harness interfaces for tests, and EIP-1193 window.ethereum typings (apps/console/src/types/ethereum.d.ts, apps/validator-ui/types/ethereum.d.ts).
  • Enforced rules via config changes: tsconfig.json (noImplicitAny, useUnknownInCatchVariables) and eslint.config.js (set @typescript-eslint/no-explicit-any to error globally and permitted any in test/demo paths), and minor Solidity cleanup (removed an unused ERC20 import).

Testing

  • Ran npm run lint:fix which executed ESLint/Prettier fixes and Solhint (warnings only); the lint fix command completed successfully.
  • Ran TypeScript checks for webapps: npm run typecheck --prefix apps/console, --prefix apps/enterprise-portal, and --prefix apps/onebox and they completed without errors.
  • Ran the test suite via npm test; unit and integration suites executed and the Hardhat tests completed (Hardhat run finished with tests passing).
  • All gates requested (lint:fix, typecheck, and test) were exercised and completed successfully in the run.

Codex Task

value = BigInt((packed as any).toString());
} else if (
typeof packed === 'object' &&
packed !== null &&

Check warning

Code scanning / CodeQL

Comparison between inconvertible types Warning

Variable 'packed' is of type date, object or regular expression, but it is compared to
an expression
of type null.

Copilot Autofix

AI 5 months ago

In general, this kind of issue is fixed by either (a) removing redundant comparisons that are already guaranteed by previous checks, or (b) restructuring the condition to ensure that values of incompatible types are not being compared in a meaningless way. Here, the function already returns early when packed is null or undefined, so the later comparison packed !== null within the typeof packed === 'object' branch cannot ever be false. That makes the packed !== null part redundant and is what CodeQL is complaining about.

The best fix is to simplify the object branch condition from:

} else if (
  typeof packed === 'object' &&
  packed !== null &&
  'toString' in packed &&
  typeof packed.toString === 'function'
) {

to:

} else if (
  typeof packed === 'object' &&
  'toString' in packed &&
  typeof packed.toString === 'function'
) {

Because null has already been handled at the top of the function, this change does not alter runtime behavior but removes the unnecessary comparison between packed and null. No new methods, imports, or definitions are needed; this is a purely local condition simplification within apps/orchestrator/bidding.ts in the decodePackedJobMetadata function.

Suggested changeset 1
apps/orchestrator/bidding.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/orchestrator/bidding.ts b/apps/orchestrator/bidding.ts
--- a/apps/orchestrator/bidding.ts
+++ b/apps/orchestrator/bidding.ts
@@ -72,7 +72,6 @@
     value = BigInt(packed);
   } else if (
     typeof packed === 'object' &&
-    packed !== null &&
     'toString' in packed &&
     typeof packed.toString === 'function'
   ) {
EOF
@@ -72,7 +72,6 @@
value = BigInt(packed);
} else if (
typeof packed === 'object' &&
packed !== null &&
'toString' in packed &&
typeof packed.toString === 'function'
) {
Copilot is powered by AI and may make mistakes. Always verify output.
value = BigInt((packed as any).toString());
} else if (
typeof packed === 'object' &&
packed !== null &&

Check warning

Code scanning / CodeQL

Comparison between inconvertible types Warning

Variable 'packed' is of type date, object or regular expression, but it is compared to
an expression
of type null.

Copilot Autofix

AI 5 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

if (typeof value === 'bigint') return value.toString();
if (
typeof value === 'object' &&
value !== null &&

Check warning

Code scanning / CodeQL

Comparison between inconvertible types Warning

Variable 'value' is of type date, object or regular expression, but it is compared to
an expression
of type null.

Copilot Autofix

AI 5 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

value = BigInt((packed as any).toString());
} else if (
typeof packed === 'object' &&
packed !== null &&

Check warning

Code scanning / CodeQL

Comparison between inconvertible types Warning

Variable 'packed' is of type date, object or regular expression, but it is compared to
an expression
of type null.

Copilot Autofix

AI 5 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Comment thread apps/validator/index.ts
value = BigInt((packed as any).toString());
} else if (
typeof packed === 'object' &&
packed !== null &&

Check warning

Code scanning / CodeQL

Comparison between inconvertible types Warning

Variable 'packed' is of type date, object or regular expression, but it is compared to
an expression
of type null.

Copilot Autofix

AI 5 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants