Skip to content

Commit 679d686

Browse files
authored
fix: TypeScript error when trying to access HTMLRules[key] (#1635)
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.
1 parent 0da2c23 commit 679d686

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

dist/core/core.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/core.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ function repeatStr(n: number, str?: string) {
156156

157157
export const HTMLHint = new HTMLHintCore()
158158

159-
Object.keys(HTMLRules).forEach((key) => {
160-
// TODO: need a fix
161-
// @ts-expect-error
162-
HTMLHint.addRule(HTMLRules[key])
159+
Object.values(HTMLRules).forEach((rule) => {
160+
HTMLHint.addRule(rule)
163161
})
164162

165163
export { HTMLRules, Reporter, HTMLParser }

0 commit comments

Comments
 (0)