Skip to content

"declare class" in a global is not visible in external files #58056

Closed
@jayshah123

Description

@jayshah123

🔎 Search Terms

"declare class" in a global is not visible in external files,
extending typescript global object with "declare class",
declared class in global not found,
typescript globals.d.ts declared global class not found

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about globals and declaration files here

⏯ Playground Link

https://github.com/jayshah123/typescript-declare-global-class-issue

💻 Code

// global.d.ts
export { };

declare global {
    var myGlobalVariable: string;
    class WorldClass {
        constructor();
        important: number;
    }
}
// index.ts
const w = new global.WorldClass(); // Property 'WorldClass' does not exist on type 'typeof globalThis'.ts(2339)
\
const h = global.myGlobalVariable;

console.log(h);

🙁 Actual behavior

Class declared in global not allowed
Screenshot 2024-04-03 at 6 47 07 PM

🙂 Expected behavior

Class declared in global should be allowed.

Additional information about the issue

No response

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