Skip to content

fix(ts): preserve exact Unicode enum values - #545

Open
robgruen wants to merge 1 commit into
mainfrom
fix/unicode-string-enum-values-541
Open

robgruen wants to merge 1 commit into
mainfrom
fix/unicode-string-enum-values-541

Conversation

@robgruen

Copy link
Copy Markdown
Contributor

Fixes #541.

Summary

  • Retrieve enum-derived string-literal type text through public compiler APIs instead of lossy raw constant/AST value payloads.
  • Keep collision-free temporary probes in each enum's lexical scope, including private namespace enums, and restore the original schema before preflight and validation.
  • Add 45 offline regressions covering high/low lone surrogates with and without BOMs, replacement-character mutations, Unicode controls, long literals/unions, folded/const/merged enums, containers, brands, diagnostics, and repair.
  • Document exact UTF-16 matching and escaped schema literals.

This is a core-only fix, separate from #538. No compiler dependency changes, decoder patches, schema code execution, diagnostic suppression, string normalization, or validation widening.

Verification

Using Node 24.22.1 and TypeScript 7.0.2:

  • Core CommonJS and ESM build: npm run build passed.
  • Test type-check: tsc -p test passed.
  • Validator, program, and failure suites: 197 tests passed, including the 45 new regressions.
  • Conditional ESM entry-point smoke test: exact value accepted; altered values rejected.
  • git diff --check passed.

The full npm test, example builds, and site build were not run.

Existing compiler limitation

Raw lone-surrogate characters in schema source still require Unicode escapes; this PR does not patch the compiler transport. The issue's escaped-schema reproduction and serialized values preserve their exact code units.

Related upstream evidence by Marc Rousavy (@mrousavy): microsoft/TypeScript#65458.

Scope follows the approved G2/G5 goals.

Fixes #541.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 04:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the change to preserve exact UTF-16 string-enum values.

No open issues 🎉

What changed in this PR

Fixes #541 in the core TypeScript validator so serialized string-enum values preserve exact UTF-16 code units, including lone surrogates and BOMs, without changing compiler dependencies or widening validation.

Changes:

  • Retrieves enum literal type text through compiler APIs using collision-free, scope-local probes, then restores the original schema.
  • Adds 45 offline regressions covering Unicode values, enum variants, containers, diagnostics, and repair.
  • Documents exact string matching and Unicode escapes for lone surrogates in schema source.
File Description
typescript/​test/​validate.test.ts Adds exact-value and rejection regressions for Unicode enums and related validation behavior.
typescript/​src/​ts/​validate.ts Replaces lossy enum-value extraction with compiler-formatted literal type text.
site/​src/​docs/​typescript/​basic-usage.md Explains UTF-16 matching and escaped schema literals.

Review effort: Balanced

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.

TypeScript validator rejects string enum values with a BOM after a lone surrogate

2 participants