Repository navigation
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: flag: isolatedDeclarationsRelated to the --isolatedDeclarations compiler flagRelated to the --isolatedDeclarations compiler flagHelp WantedYou can do thisYou can do this
Milestone
Description
🔍 Search Terms
isolated declarations, computed properties
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Now that #60052 allows for (some) computed properties in in .d.ts files I think the next step is for --isolatedDeclaration to be updated to not error and to emit the computed properties. Opening this issue if helpful to track this work.
I believe the previous plan (#58800) to introduce a new syntactic marker is no longer required.
Related issues: #58533 #60818 #61068
📃 Motivating Example
export const prop: unique symbol = Symbol();
export class MyClass {
[prop] = () => Math.random();
}@isolatedDeclarations: false
export declare const prop: unique symbol;
export declare class MyClass {
[prop]: () => number;
}@isolatedDeclarations: true (current 🙁)
ts(9038) Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.export declare const prop: unique symbol;
export declare class MyClass {
}@isolatedDeclarations: true (future 🚀 )
No error and same emit as @isolatedDeclarations: false
export declare const prop: unique symbol;
export declare class MyClass {
[prop]: () => number;
}💻 Use Cases
The primary use case is enabling isolated declarations at scale on large codebases that make heavy use of computed properties.
Reacted by Rob Palmer, Brad Zacher, Jeremy Banka, StevenGBrown and Jan Olaf Martin
Reacted by Tristan Smith
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: flag: isolatedDeclarationsRelated to the --isolatedDeclarations compiler flagRelated to the --isolatedDeclarations compiler flagHelp WantedYou can do thisYou can do this
Activity
bradzacher commentedon Jun 19, 2025
I was actually about to post in the discord about this!
In the canva codebase we have:
Where
$mobxis declared asexport declare const $mobx: unique symbol;Currently TS errors on this code, but I don't see how you can resolve this error at all.
bradzacher commentedon Jun 19, 2025
Question: is there a way around this?
I am trying to rollout ID to our codebase at Canva but it looks like I'm blocked by this.
TJLSmith0831 commentedon Jun 19, 2025
Working on my OSS contributions. Mind if I give this a shot?
bradzacher commentedon Jun 19, 2025
I found this VERY HACKY workaround for now:
It's ugly but it works and unblocks me for now, at least.
teague2 commentedon Sep 19, 2025
For anyone alse struggling with isolatedDeclarations i finally got something similar to work.
I was using mixins and had to figure out a way to dynamically create brand mixin classes.
I'm sure there is a simpler solution but the BrandedClass return type fixed most of the issues.
bradzacher commentedon Sep 19, 2025
Alexander Teague (@teague2) if you use a
#privateproperty then it should act like a brand as well. True private properties essentially make a class declaration a nominal type then your brand check can just bethis.#brand === config.brandchriskrycho commentedon Sep 23, 2026
Note for other folks who hit this: the assignment from constructor (a) doesn’t work with
privatefields for obvious reasons and (b) also doesn’t work for the “phantom type” pattern, which is where I most often reach for this because if you don’t export the declared symbol, it’s impossible for folks to try to access the field, it doesn’t autocomplete, etc.Preserve computed property names in isolated declaration emit