Skip to content

chore: improve types by reducing the any type usage and type casting#2771

Merged
tatomyr merged 1 commit into
mainfrom
chore/refactor-types--2
Apr 28, 2026
Merged

chore: improve types by reducing the any type usage and type casting#2771
tatomyr merged 1 commit into
mainfrom
chore/refactor-types--2

Conversation

@tatomyr
Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr commented Apr 24, 2026

What/Why/How?

Improved typing by reducing the any type usage and type casting

Testing

Pipeline and E2E passed.

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Mostly type-safety improvements, but resolve.ts changes the $ref pointer-walk logic (object/array handling and anchor collection timing), which could affect resolution behavior across bundling/linting.

Overview
Reduces any usage across core utilities/rules by switching to unknown, tightening option/return types, and removing several casts (e.g., JSON formatter output, filter helpers, env/platform check, AJV error formatting, stats visitors).

Hardens reference resolution in resolve.ts by treating traversed nodes as unknown, guarding walks with isPlainObject/Array.isArray, and correctly following JSON Pointer segments through both objects and arrays (including when encountering nested $refs). It also adjusts when $anchor entries are collected and tightens rule exports/casts in the OAS2/OAS3 rule registries.

Reviewed by Cursor Bugbot for commit 7e65ed0. Bugbot is set up for automated code reviews on this repo. Configure here.

@tatomyr tatomyr self-assigned this Apr 24, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: 7e65ed0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tatomyr tatomyr force-pushed the chore/refactor-types--2 branch from c3d2fa5 to 403a80e Compare April 24, 2026 06:10
@tatomyr tatomyr added the snapshot Create experimental release PR label Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1777011056 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1777011056
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1777011056
# or
npm install @redocly/respect-core@0.0.0-snapshot.1777011056

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 80.08% (🎯 80%) 7129 / 8902
🔵 Statements 79.49% (🎯 79%) 7408 / 9319
🔵 Functions 83.47% (🎯 83%) 1430 / 1713
🔵 Branches 71.57% (🎯 71%) 4826 / 6743
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/env.ts 100% 85.71% 100% 100%
packages/core/src/logger.ts 95% 80% 100% 95% 50
packages/core/src/resolve.ts 95.26% 94.44% 100% 95.12% 88, 275, 353-358, 450-458
packages/core/src/bundle/bundle-visitor.ts 64.75% 61.06% 100% 64.75% 30, 34-42, 49-57, 64, 73, 81, 86-107, 172-184, 201-202, 219-225, 236-237, 274
packages/core/src/decorators/common/filters/filter-helper.ts 97.56% 94.28% 100% 97.36% 68
packages/core/src/format/format.ts 51.59% 43.75% 58.06% 51.39% 25, 67-68, 113, 117-143, 161, 165, 173-191, 200-306, 311, 324-330, 355-361, 413-426, 440-441, 470
packages/core/src/rules/ajv.ts 93.87% 91.66% 88.88% 97.77% 52, 133
packages/core/src/rules/async2/no-channel-trailing-slash.ts 100% 100% 100% 100%
packages/core/src/rules/catalog-entity/entity-key-valid.ts 100% 100% 100% 100%
packages/core/src/rules/common/no-invalid-parameter-examples.ts 100% 100% 100% 100%
packages/core/src/rules/common/no-invalid-schema-examples.ts 100% 100% 100% 100%
packages/core/src/rules/common/no-path-trailing-slash.ts 100% 100% 100% 100%
packages/core/src/rules/common/path-http-verbs-order.ts 92.85% 85.71% 100% 91.66% 11
packages/core/src/rules/common/path-segment-plural.ts 21.42% 0% 50% 23.07% 12-26
packages/core/src/rules/oas2/index.ts 100% 100% 100% 100%
packages/core/src/rules/oas3/index.ts 100% 100% 100% 100%
packages/core/src/rules/other/stats.ts 5.66% 0% 0% 5.66% 13-80, 87-138, 145-198
Generated in workflow #9658 for commit 7e65ed0 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

CLI Version Mean Time ± Std Dev (s) Relative Performance (Lower is Faster)
cli-latest 3.091s ± 0.044s ▓ 1.00x (Fastest)
cli-next 3.134s ± 0.025s ▓ 1.01x


const segments = pointer;
for (const segment of segments) {
if (typeof target !== 'object') {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the guard with explicit Array/Object detection.

resolvedRef = await followRef(targetDoc, target, pushRef(refStack, target));
targetDoc = resolvedRef.document || targetDoc;

if (typeof resolvedRef.node !== 'object') {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the else block below.

@tatomyr tatomyr marked this pull request as ready for review April 24, 2026 08:16
@tatomyr tatomyr requested a review from a team as a code owner April 24, 2026 08:16
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 403a80e. Configure here.

Comment thread packages/core/src/rules/other/stats.ts
Comment thread packages/core/src/rules/oas2/index.ts
@tatomyr tatomyr force-pushed the chore/refactor-types--2 branch from 403a80e to db4207a Compare April 24, 2026 11:31
@tatomyr tatomyr requested a review from DmitryAnansky April 24, 2026 12:52
@tatomyr tatomyr force-pushed the chore/refactor-types--2 branch from db4207a to 7e65ed0 Compare April 28, 2026 14:51
@tatomyr tatomyr merged commit 0c2456c into main Apr 28, 2026
45 checks passed
@tatomyr tatomyr deleted the chore/refactor-types--2 branch April 28, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changeset needed snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants