Skip to content

Ambient external module name incorrectly appears in keyof typeof globalThisΒ #48147

Closed

Description

@saucesteals

Bug Report

πŸ”Ž Search Terms

  • keyof typeof globalThis

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about types

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// Module declaration ( should not concern globalThis ? )
declare module "foo" {}

type globalType = typeof globalThis

type globalKey = keyof globalType

globalThis["foo"]
// Property 'foo' does not exist on type 'typeof globalThis'.

const f: globalKey = "foo"
// OK

// See playground for more examples

πŸ™ Actual behavior

"foo" is a valid key/property of typeof globalThis

πŸ™‚ Expected behavior

"foo" should not be a valid key/property of typeof globalThis as globalThis["foo"] is not valid

Activity

  1. changed the title [-]Incorrect globalThis type[/-] [+]Ambient external module name incorrectly appears in `keyof typeof globalThis`[/+] on Mar 8, 2022
  2. sandersn commented on May 3, 2022

    @sandersn
    Member

    It took me a long time to figure out, but it turns out that globalThis["\"foo\""] is also erroneously valid. keyof typeof globalThis flattens "\"foo\"" to "foo", which makes the bug more obvious.

  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions