Skip to content

Declarations in declare global can have export modifiers #64430

Description

Is it intentional that declarations in declare global can have export modifiers?

export {}

declare global {
    // allowed!
    export interface Oops {
    }
}

I want to say "no", but... I'm not sure who that would help at this point - maybe a check would make sure you're doing what you think you're doing (whatever that is).

Somewhat related is:

Activity

  1. yksr-melt commented on Sep 29, 2026

    @yksr-melt
    Contributor

    Short answer: export inside declare global isn't an error, and in the normal case it does nothing. Everything in a declare global block becomes global anyway, because the block is an implicit export context. This is the same in 6.0 and the Go port (7.1-dev).

    But it isn't completely ignored. There are two cases where it matters:

    1. Mixing exported and non-exported declarations is an error.

      declare global {
          export interface A { x: number }
          interface A { y: number } // TS2395: must be all exported or all local
      }

      getEffectiveDeclarationFlags deliberately skips the implicit-export treatment for global augmentation blocks. So this one check distinguishes export from no export, even though binding doesn't.

    2. An export declaration inside the block drops the non-exported members from the global scope.

      declare global {
          export interface B {} // becomes global
          interface C {}        // does not ("Cannot find name 'C'" elsewhere)
          export {};            // already TS2666
      }

    Compat: patterns like declare global { export const THREE: typeof _three; } show up in UMD-style typings (e.g. the checkMergedGlobalUMDSymbol test), so turning this into an error would be a breaking change.

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

    Needs InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions