Skip to content
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

fix globals types #50278

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix globals types #50278

wants to merge 1 commit into from

Conversation

MoOx
Copy link
Contributor

@MoOx MoOx commented Mar 26, 2025

Summary:

I am sharing code with the web using Next.js. Turbopack doesn't allow easy injection (yet?) for __DEV__ that's why I detected this issue when trying to inject this way:

globalThis.__DEV__ = process.env.NODE_ENV !== "production";

This code is currently throwing this error (with ts 5.8):

Property '__DEV__' does not exist on type 'typeof globalThis'.ts(2339)

Currently some exported types use const keywords. But this doesn't look right as explained in TypeScript 3.4 changelog.

Note that global variables declared with let and const don’t show up on globalThis.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis

This means with current const declaration, this defined types are not accessible, which defeat the purpose.

Changelog:

[GENERAL] [FIXED] - globalThis now properly expose global vars

Test Plan:

This PR should fix this problem (currently works for me using patch-package).

Before this change

image

After this change

image

Currently some exported types use const keywords. 
But this doesn't look right as explained in TypeScript 3.4 changelog.

> Note that global variables declared with let and const don’t show up on globalThis.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#type-checking-for-globalthis

This means with current const declaration, this defined types are not accessible, which defeat the purpose.

This PR should fix this problem (currently works for me using patch-package).
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants