-
Notifications
You must be signed in to change notification settings - Fork 12.8k
"declare class" in a global is not visible in external files #58056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Your "Playground" link does not work and leads to a 404. |
It's a github link as I need more than one file: https://github.com/jayshah123/typescript-declare-global-class-issue |
And I'm telling you that your link doesn't work, it leads to a 404 page. Perhaps you have set it to private. |
See #39504 (comment)
If you still want to do this, try this workaround. declare global {
namespace globalThis {
class WorldClass {
constructor();
important: number;
}
export { WorldClass }
}
}
const w = new global.WorldClass(); // OK |
My bad, made it public |
Is this a common pattern for globals class declaration - /**
* The URL interface represents an object providing static methods used for creating object URLs.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL)
*/
interface URL {
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
readonly searchParams: URLSearchParams;
username: string;
toJSON(): string;
}
declare var URL: {
prototype: URL;
new(url: string | URL, base?: string | URL): URL;
canParse(url: string | URL, base?: string): boolean;
createObjectURL(obj: Blob | MediaSource): string;
revokeObjectURL(url: string): void;
}; if the behavior mentioned in the issue description is an expcted one, |
The behavior mentioned matches JS runtime behavior: <script>
class Foo {}
console.log(Foo); // [class Foo]
console.log(globalThis.Foo); // undefined
</script> I don't think it needs to be documented separately if the types match the runtime reality. |
🔎 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
⏯ Playground Link
https://github.com/jayshah123/typescript-declare-global-class-issue
💻 Code
🙁 Actual behavior
Class declared in global not allowed

🙂 Expected behavior
Class declared in global should be allowed.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: