Skip to content

fix(types): add RegExp to Mode.keywords to match LanguageDetail.keywords#4383

Open
KJyang-0114 wants to merge 1 commit intohighlightjs:mainfrom
KJyang-0114:main
Open

fix(types): add RegExp to Mode.keywords to match LanguageDetail.keywords#4383
KJyang-0114 wants to merge 1 commit intohighlightjs:mainfrom
KJyang-0114:main

Conversation

@KJyang-0114
Copy link

Summary

Fixes #4365 — TypeScript errors when dynamically importing language modules due to $pattern: RegExp in keywords not matching the type definition.

Root Cause

Language = LanguageDetail & Partial<Mode>

  • LanguageDetail.keywords: string | string[] | Record<string, string | string[] | RegExp>
  • Mode.keywords: string | string[] | Record<string, string | string[]> ❌ (missing RegExp)

Since Language is an intersection, TypeScript requires the narrower Mode type to be satisfied. When language modules include $pattern: RegExp in their keywords object, the type check fails.

Fix

Updated Mode.keywords in types/index.d.ts to include RegExp:

- keywords?: string | string[] | Record<string, string | string[]>
+ keywords?: string | string[] | Record<string, string | string[] | RegExp>

Validation

  • Build: npm run build
  • Test: npm run test
  • Type change is purely additive (no breaking changes)

Risk & Rollback

  • Risk: Minimal — purely additive type change
  • Rollback: Revert single line in types/index.d.ts

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.

[BUG] Type 'Promise<typeof import("...highlight.js/es/languages/sql")>' is not assignable to type 'Promise<{ default: LanguageFn; }>'.

1 participant