Skip to content

fix: TypeScript error when trying to access HTMLRules[key] #1635

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

Merged
merged 1 commit into from
Jun 6, 2025

Conversation

coliff
Copy link
Member

@coliff coliff commented Jun 6, 2025

The original code had a TypeScript error when trying to access HTMLRules[key] using dynamic key access: )

Solution
I replaced the problematic code with a cleaner, more type-safe approach using Object.values(): )

Why this works better:

  • Type Safety: Object.values() properly preserves the type information, so TypeScript knows that each rule is of type Rule
  • Cleaner Code: No need for type assertions or @ts-expect-error comments
  • More Direct: We directly iterate over the rule objects instead of getting keys and then accessing values
  • ESLint Compliant: No linting errors about using any type

Verification:
✅ TypeScript compilation passes (npm run build succeeded)
✅ All tests pass (324 tests passed)
✅ Linting passes (no warnings or errors)
✅ Code formatting is correct

The issue has been completely resolved with a clean, type-safe solution that maintains all existing functionality while eliminating the TypeScript error.

The original code had a TypeScript error when trying to access HTMLRules[key] using dynamic key access:
)
Solution
I replaced the problematic code with a cleaner, more type-safe approach using Object.values():
)
Why this works better:
Type Safety: Object.values() properly preserves the type information, so TypeScript knows that each rule is of type Rule
Cleaner Code: No need for type assertions or @ts-expect-error comments
More Direct: We directly iterate over the rule objects instead of getting keys and then accessing values
ESLint Compliant: No linting errors about using any type
Verification:
✅ TypeScript compilation passes (npm run build succeeded)
✅ All tests pass (324 tests passed)
✅ Linting passes (no warnings or errors)
✅ Code formatting is correct
The issue has been completely resolved with a clean, type-safe solution that maintains all existing functionality while eliminating the TypeScript error.
@coliff coliff requested a review from thedaviddias as a code owner June 6, 2025 14:03
gemini-code-assist[bot]

This comment was marked as resolved.

Copy link

codecov bot commented Jun 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (95e6a13) to head (e48794c).
Report is 60 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main     #1635      +/-   ##
===========================================
+ Coverage   96.99%   100.00%   +3.00%     
===========================================
  Files           2         1       -1     
  Lines        1628         1    -1627     
  Branches      335         0     -335     
===========================================
- Hits         1579         1    -1578     
+ Misses         49         0      -49     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0da2c23...e48794c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coliff coliff merged commit 679d686 into main Jun 6, 2025
17 checks passed
@coliff coliff deleted the dev/coliff/fix-tslint-error-issue branch June 6, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant