You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Preserve computed property in --isolatedDeclarations emit #61892
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.
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.
typeBrandedClass={new(): {};// this could be any interfaceisBrand: (value: unknown)=>boolean;};exportconstBranded=(config: {brand: string}): BrandedClass=>{constbrand: unique symbol=Symbol.for(config.brand);returnclass{readonly[brand]: boolean=true;staticreadonly[brand]: boolean=true;staticisBrand(value: unknown){returnisBranded(value,config.brand);}};};exportfunctionisBranded(value: unknown,brand: string): value is BrandedClass{constbrandSymbol=Symbol.for(brand);returnvalue!==null&&typeofvalue==='object'&&brandSymbolinvalue&&value[brandSymbol]===true;}
Alexander Teague (@teague2) if you use a #private property 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 be this.#brand === config.brand
Note for other folks who hit this: the assignment from constructor (a) doesn’t work with private fields 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.
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