Skip to content

Avoid typescript error TS7017 by explicitly casting global #84

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

Closed
wants to merge 1 commit into from

Conversation

ggilles
Copy link

@ggilles ggilles commented Jun 11, 2025

First, thanks for that useful module.

We found-out when upgrading to version 6.0 that running tsc -noEmit on a project using that module would trigger the following error:

error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

This pull-request addresses this by explicitly casting global to any before using it.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This avoids this specific error when using react-native-file-logger and running `tsc -noEmit`:

error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
@ggilles
Copy link
Author

ggilles commented Jun 30, 2025

I'm getting a little worried to see no reaction to this PR. @alixf @fdrault is the package alive ?

@mperinet
Copy link

@ggilles I can't reproduce your error when running tsc --noEmit inside the example app of react-native-file-logger, can you tell me which TypeScript version you are using ?

@mperinet
Copy link

mperinet commented Jun 30, 2025

@ggilles It appears that example app is using a tsconfig that extends expo/tsconfig.base which exclude node_modules :
"exclude": ["**node_modules**", "babel.config.js", "metro.config.js", "jest.config.js"]. I would suggest that you explicitly exclude node_modules as well (or at least this module). Thanks to @alois-beto pointing out this !

@ggilles
Copy link
Author

ggilles commented Jun 30, 2025

@mperinet Using TypeScript version 5.7.3 here. Thanks for the suggestion, that could also be a good enough workaround.

I still think that merging this pull-request makes sense: this is the only package we use that is having such problem.

@alois-beto
Copy link
Contributor

Hello,

Thank you for your contribution. I understand your point of view, but from our side, we don't see a reason to cast global as any, since we are not encountering any TypeScript errors in our library's source code. Internally, we include the @types/node package, which provides the necessary type definition for global.

Additionally, the file in question (src/index.ts) is not used at runtime. We compile our TypeScript code before publishing to NPM, and consumers (including React Native projects) use the compiled output (dist/index.js), not the source files.

In short, we don't believe there's a need to fix a problem we are not experiencing.

As a general note, TypeScript should not attempt to validate code inside node_modules, since that code is external to your project and not your responsibility if it contains errors.

For these reasons, I’m going to close this PR.

Thanks again!

@alois-beto alois-beto closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants