microsoft / microsoft/TypeScript

Allow merging enums with undefined

Open
#56,579 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

enum merge undefined

✅ Viability Checklist
⭐ Suggestion

It can sometimes be useful to augment the types for a module to indicate that an exported enum is optional. There's no way I can find in TypeScript to do that right now. "Enum declarations can only merge with namespace or other enum declarations."

📃 Motivating Example

For example API consumers may need to support versions of a package that don't include a recently added enum.

How about allowing a ? before the { for an enum?

declare module 'typescript' {
  enum JSDocParsingMode? {}
}
💻 Use Cases

In typescript-eslint we want to always treat ts.JSDocParsingMode as optional. It was added in a more recent version of TypeScript than our backwards compatibility extends. But there's no way to mark it as | undefined.

Even if we do remember to always ts.JSDocParsingMode?.ParseAll and so on, doing so violates https://typescript-eslint.io/rules/no-unnecessary-condition.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or specific entry points are named. Start by examining how enum declarations merge and how the motivating module augmentation is type-checked. Done would mean a supported way to mark the exported enum as optional while preserving the stated compatibility and runtime constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.