Skip to content

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

Merged
joshgoebel merged 1 commit into
highlightjs:mainfrom
KJyang-0114:main
Jul 6, 2026
Merged

fix(types): add RegExp to Mode.keywords to match LanguageDetail.keywords#4383
joshgoebel merged 1 commit into
highlightjs:mainfrom
KJyang-0114:main

Conversation

@KJyang-0114

Copy link
Copy Markdown
Contributor

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

@joshgoebel

Copy link
Copy Markdown
Member

Ok, maybe sense... I wonder if long-term to avoid this edge case typing we should just have keyword_pattern: regex as a top level key... any thoughts?

@joshgoebel
joshgoebel merged commit 5a5027a into highlightjs:main Jul 6, 2026
19 checks passed
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +6 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.2 KB +2 B
es/highlight.min.js 8.19 KB 8.2 KB +2 B
highlight.min.js 8.23 KB 8.23 KB +2 B

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; }>'.

2 participants