microsoft / microsoft/TypeScript

[ID-Prep] Explicit type annotation of const replaced with initializer in declaration emit

Open
#57,442 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: flag: isolatedDeclarations Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

The [ID-prep] set of issues aligns Declaration Emit with the forthcoming Isolated Declarations feature.

🔎 Search Terms

declarations type annotation const not preserved

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

Playground Link

💻 Code
enum E { "some value" = 1 };
const e: typeof E["some value"] = E["some value"];
🙁 Actual behavior

e is emitted in declarations as declare const e = E["some value"];

🙂 Expected behavior

e should have in declarations the type that was manually declared

Additional information about the issue

No response

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

Reproduce the declaration emit behavior from the linked Playground using the enum and explicitly typed const shown in the issue. Trace the declaration-emit path for that declaration and verify that the generated declaration preserves the manually written type instead of using the initializer expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.