Skip to content

fix globals types (__DEV__ is incorrectly exposed and unrecognized, as well as others var)#50278

Open
MoOx wants to merge 1 commit into
react:mainfrom
MoOx:patch-5
Open

fix globals types (__DEV__ is incorrectly exposed and unrecognized, as well as others var)#50278
MoOx wants to merge 1 commit into
react:mainfrom
MoOx:patch-5

Conversation

@MoOx

@MoOx MoOx commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

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
@MoOx MoOx changed the title fix globals types fix globals types (__DEV__ is incorrectly exposed and unrecognized, as well as others var) Apr 12, 2025
@MoOx

MoOx commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

Could anyone have a look at this PR ? There is literally something incorrect according to TypeScript 3.4 changelog

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

@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 18, 2026
@MoOx

MoOx commented Jan 18, 2026

Copy link
Copy Markdown
Contributor Author

Still relevant

@react-native-bot react-native-bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 19, 2026
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.

3 participants