8000 TypeScript Error: global.__turboModuleProxy type definition missing for React Native Turbo Modules · Issue #773 · morenoh149/react-native-contacts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TypeScript Error: global.__turboModuleProxy type definition missing for React Native Turbo Modules #773

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

Open
KMJ-007 opened this issue Feb 14, 2025 · 6 comments

Comments

@KMJ-007
Copy link
KMJ-007 commented Feb 14, 2025

When using react-native-contacts with TypeScript strict mode enabled, the following type error occurs:

This error occurs because the package uses React Native's Turbo Modules feature but doesn't include the necessary type definitions for the global __turboModuleProxy property.

Environment

  • react-native-contacts: ^8.0.4
  • react-native: 0.76.7
  • typescript: ~5.3.3
  • expo: ~52.0.33
  • Platform: iOS/Android

Steps to Reproduce

  1. Create a new React Native project with TypeScript
  2. Enable strict: true in tsconfig.json
  3. Install react-native-contacts
  4. Run TypeScript type checking

Expected Behavior

TypeScript should recognize the __turboModuleProxy property on the global object as it's a valid React Native Turbo Modules property.

Additional Context

This is related to React Native's Turbo Modules architecture. The property is valid and works at runtime, but lacks proper TypeScript definitions.

@therveux
Copy link

Same issue here !

@fbp93
Copy link
fbp93 commented Feb 27, 2025

+1

@SimpleCreations
Copy link

Workaround

globals.d.ts

declare global {
  // https://github.com/morenoh149/react-native-contacts/issues/773
  declare const global: typeof globalThis & { __turboModuleProxy: unknown }
}

export {}

@KMJ-007
Copy link
Author
KMJ-007 commented Feb 28, 2025

the fact that i can't ingore node_modules in tsc is such a pain, we need to work on the tooling better.

i solved(workaround) it using this:

react-native-contacts.d.ts

declare global {
	var __turboModuleProxy: unknown | null;
}

export {};

@wr-lhiggitt
Copy link

Other packages, such as FullStory use the @ts-expect-error directive:

// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

Becuase of this adding the global declaration breaks other packages and instead i've opted to patch react-native-contacts:

File name: react-native-contacts+8.0.4.patch

diff --git a/node_modules/react-native-contacts/index.ts b/node_modules/react-native-contacts/index.ts
index 9f15471..72f1834 100644
--- a/node_modules/react-native-contacts/index.ts
+++ b/node_modules/react-native-contacts/index.ts
@@ -2,6 +2,7 @@ import { NativeModules } from "react-native";
 import NativeContacts from "./src/NativeContacts";
 import { Contact, PermissionType } from "./type";
 
+// @ts-expect-error
 const isTurboModuleEnabled = global.__turboModuleProxy != null;
 const Contacts = isTurboModuleEnabled ? NativeContacts : NativeModules.Contacts;

@morenoh149
Copy link
Owner

I think we remove usage of it here d927fec

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

No branches or pull requests

6 participants
0