microsoft / microsoft/TypeScript
Isolated declarations uses type information when emitting computed object keys
Open
Nobody has claimed this yet.
Domain: Declaration Emit
Domain: flag: isolatedDeclarations
Possible Improvement
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
- isolated declarations
- computed keys
- object literals
🕗 Version & Regression Information
5.5.0-dev.20240514
⏯ Playground Link
💻 Code
export const Key = "theKey";
declare global {
export const GlobalKey = "theGlobalKey"
export const UniqueSymbol: unique symbol;
export const NonUniqueSymbol: symbol;
}
export const A = {
[Key]: true,
[Symbol.toStringTag]: false,
[UniqueSymbol]: false,
[GlobalKey]: false,
}
🙁 Actual behavior
TypeScript is emitting the computed property keys with type information that can not be determined without a type checker.
export declare const Key = "theKey";
declare global {
export const GlobalKey = "theGlobalKey";
export const UniqueSymbol: unique symbol;
export const NonUniqueSymbol: symbol;
}
export declare const A: {
theKey: boolean;
[Symbol.toStringTag]: boolean;
[UniqueSymbol]: boolean;
theGlobalKey: boolean;
};
🙂 Expected behavior
export declare const Key = "theKey";
declare global {
export const GlobalKey = "theGlobalKey";
export const UniqueSymbol: unique symbol;
export const NonUniqueSymbol: symbol;
}
export declare const A: {
[Key]: true,
[Symbol.toStringTag]: false,
[UniqueSymbol]: false,
[GlobalKey]: false,
};
Additional information about the issue
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Playground reproduction and the isolated-declarations declaration-emission path. Compare the actual and expected output for computed keys involving string constants, Symbol.toStringTag, unique symbols, and global constants; done means the emitted declaration preserves the computed keys without requiring type information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100