-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Property does not exist on globalThis
immediately after declaring it
#39504
Comments
That’s because This is also why microsoft/TypeScript-DOM-lib-generator#858 doesn’t quite work the way I intended. |
😢 Hmm, in this case we actually want a varlike global class, though, hrm |
How about supporting declare module "buf" {
global {
var class Buffer {}
}
import Buf = globalThis.Buffer;
export { Buf as Buffer };
} |
To explain this differently for other people, this behavior is because it works like the following in actual browser script tags (assuming that's what the TypeScript global declarations are emulating): <script>
const foo = 123;
var bar = 456;
let baz = 789;
</script>
<script type="module">
console.log(foo); // logs "123"
console.log(globalThis.foo); // logs "undefined"
console.log(bar); // logs "456"
console.log(globalThis.bar); // logs "456" (not undefined!)
console.log(baz); // logs "789"
console.log(globalThis.baz); // logs "undefined"
</script> Only the |
Code
Expected behavior:
No errors.
Actual behavior:
Property 'Buffer' does not exist on type 'typeof globalThis'.
Playground Link
The text was updated successfully, but these errors were encountered: