Skip to content

isolatedDeclarations: Inconsistent type requirement for as const when using satisfies #62476

Closed as duplicate

Description

Acknowledgement

  • 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.

Activity

  1. MartinJohns commented on Sep 22, 2025

    @MartinJohns
    Contributor

    Duplicate of #58397.

  2. barryam3 commented on Nov 21, 2025

    @barryam3

    Since #58397 is locked I am replying here.

    If the satisfies operator doesn't change the type of the inferred expression, then it's always safe to rewrite this into two lines:

    export const foo = {
     a: 42
    } as const;
    foo satisfies Record<string, number>;

    ― Ryan Cavanaugh (@RyanCavanaugh)

    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).

    ― 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:

    export const foo = {  // 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)
    } as const satisfies Record<string, { a: number }>;
    
    export const bar = {
        a: { a: 42 },
        b: { a: 42, b: 42 },  // Allowed
        c: {}  // Error, but not inline
    } as const;
    bar satisfies Record<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.
  3. locked as resolved and limited conversation to collaborators on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions