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
isolatedDeclarations: Inconsistent type requirement for as const when using satisfies #62476
I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
When setting isolatedDeclarations, I see that as const exports can omit explicitly adding type annotations. This is awesome, especially when working with large structures where doubling the typing for the type would be very tedious and a pain to maintain. I have noticed however, that if you do as const satisfies SomeType, then suddenly you need to explicitly add type again (playground link). Afaik. the emitted d.ts would be the same regardless of satisfies (and especially so with as const?), so is there any reason why this restriction can't be relaxed to support this?
I also gave OXC's isolated declaration transformer a go to see how it would react to this, and it seems to resolve the .d.ts fine just fine without any issues. Here is a link to a stackblitz.
While visually will take some getting used to, I suppose that's a good enough solution (thank you for taking the time to think > of and provide one and not just mansplaining how things work).
Unfortunately this isn't quite as good if you want to ensure that the type doesn't contain any extraneous fields. Here's an example:
exportconstfoo={// Variable must have an explicit type annotation with --isolatedDeclarations.(9010)a: {a: 42},b: {a: 42,b: 42},// Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.(2353)c: {}// Property 'a' is missing in type '{}' but required in type '{ a: number; }'.(2741)}asconstsatisfiesRecord<string,{a: number}>;exportconstbar={a: {a: 42},b: {a: 42,b: 42},// Allowedc: {}// Error, but not inline}asconst;barsatisfiesRecord<string,{a: number}>/*Type '{ readonly a: { readonly a: 42; }; readonly b: { readonly a: 42; readonly b: 42; }; readonly c: {}; }' does not satisfy the expected type 'Record<string, { a: number; }>'. Property 'c' is incompatible with index signature. Property 'a' is missing in type '{}' but required in type '{ a: number; }'.(1360)*/
The as const satisfies version works as I would prefer except that it gives an error with --isolatedDeclarations.
The delayed satisfies workaround has a couple of limitations:
It doesn't enforce that unknown properties are not present.
If a field does not satisfy the type, the error is deferred until the satisfies clause and contains much more text, whereas in the as const satisfies case it appears inline and is more succinct.
Activity
MartinJohns commentedon Sep 22, 2025
Duplicate of #58397.
satisfiesto a const expression makes it require explicit type annotation #58397barryam3 commentedon Nov 21, 2025
Since #58397 is locked I am replying here.
― Ryan Cavanaugh (@RyanCavanaugh)
― michaelm (@MichaelMitchell-at)
Unfortunately this isn't quite as good if you want to ensure that the type doesn't contain any extraneous fields. Here's an example:
The
as const satisfiesversion works as I would prefer except that it gives an error with--isolatedDeclarations.The delayed
satisfiesworkaround has a couple of limitations:satisfiesclause and contains much more text, whereas in theas const satisfiescase it appears inline and is more succinct.