react-native-maps: TypeScript errors now being reported from command line check due to raw .tsx files type errors

Summary

I started getting TypeScript errors when running my checks via command line, regardless of exluding node_modules (see output below). According to ChatGPT this is due to react-native-maps publishing raw .tsx and .ts files instead of publishing precompiled .js and .d.ts files (with type errors in them) like other libraries. I am not super familiar with publishing libraries so I am just quoting what I have read. According to this, when you run a TypeScript check from the command line, TypeScript now treats all react-native-maps imports as internal files instead of external modules; therefore when any of these contain type errors, there is no way to ignore them.

My errors list:

Errors  Files
     1  node_modules/react-native-maps/src/createFabricMap.tsx:46
     7  node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:864
     7  node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1043
     6  node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:296

Full error output:

node_modules/react-native-maps/src/createFabricMap.tsx:46:49 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

46       const fabricRef = useRef<React.ElementRef<typeof ViewComponent>>(null);
                                                   ~~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:864:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

864     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:870:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

870     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:875:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

875     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:881:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

881     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:887:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

887     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:894:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

894     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts:900:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

900     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1043:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1043     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1049:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1049     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1054:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1054     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1060:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1060     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1066:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1066     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1073:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1073     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMapView.ts:1080:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

1080     viewRef: React.ElementRef<React.ComponentType>,
                                   ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:296:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.
  Type 'FunctionComponent<{}>' is not assignable to type 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.
    Property '$$typeof' is missing in type 'FunctionComponent<{}>' but required in type 'ForwardRefExoticComponent<any>'.

296     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:562:18
    562         readonly $$typeof: symbol;
                         ~~~~~~~~
    '$$typeof' is declared here.

node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:302:31 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

302     viewRef: React.ElementRef<React.ComponentType>,
                                  ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:306:43 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

306   showCallout: (viewRef: React.ElementRef<React.ComponentType>) => void;
                                              ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:307:43 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

307   hideCallout: (viewRef: React.ElementRef<React.ComponentType>) => void;
                                              ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:308:45 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

308   redrawCallout: (viewRef: React.ElementRef<React.ComponentType>) => void;
                                                ~~~~~~~~~~~~~~~~~~~

node_modules/react-native-maps/src/specs/NativeComponentMarker.ts:309:38 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode) | keyof IntrinsicElements'.

309   redraw: (viewRef: React.ElementRef<React.ComponentType>) => void;

Reproducible sample code

N/A

Steps to reproduce

Run a TypeScript check via command line in a project using any react-native-maps library imports (i.e. tsc --noEmit --skipLibCheck). You will get errors with the latest version.

Expected result

The TypeScript check should not be checking any react-native-maps library imports, since they are from node_modules.

Actual result

I get several errors after completing a command line TypeScript check (referenced above).

React Native Maps Version

1.23.7

What platforms are you seeing the problem on?

Android, iOS (Google Maps)

React Native Version

0.79.2

What version of Expo are you using?

Not using Expo

Device(s)

N/A

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 34

Most upvoted comments

This patch adds a @ts-nocheck to the top of all the files causing the type errors. The map seems to still be working fine with it.

react-native-maps+1.23.8.patch

diff --git a/node_modules/react-native-maps/src/createFabricMap.tsx b/node_modules/react-native-maps/src/createFabricMap.tsx
index 0000000..0000000 100644
--- a/node_modules/react-native-maps/src/createFabricMap.tsx
+++ b/node_modules/react-native-maps/src/createFabricMap.tsx
@@ -1,3 +1,4 @@
+// @ts-nocheck
 import React, {forwardRef, useImperativeHandle, useRef} from 'react';
 import {findNodeHandle} from 'react-native';
 import type {LatLng, Point, Region} from './sharedTypes';
diff --git a/node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts b/node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts
index 0000000..0000000 100644
--- a/node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts
+++ b/node_modules/react-native-maps/src/specs/NativeComponentGoogleMapView.ts
@@ -1,3 +1,4 @@
+// @ts-nocheck
 import type {HostComponent, ViewProps, ColorValue} from 'react-native';
 
 import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
diff --git a/node_modules/react-native-maps/src/specs/NativeComponentMapView.ts b/node_modules/react-native-maps/src/specs/NativeComponentMapView.ts
index 0000000..0000000 100644
--- a/node_modules/react-native-maps/src/specs/NativeComponentMapView.ts
+++ b/node_modules/react-native-maps/src/specs/NativeComponentMapView.ts
@@ -1,3 +1,4 @@
+// @ts-nocheck
 import type {HostComponent, ViewProps, ColorValue} from 'react-native';
 
 import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
diff --git a/node_modules/react-native-maps/src/specs/NativeComponentMarker.ts b/node_modules/react-native-maps/src/specs/NativeComponentMarker.ts
index 0000000..0000000 100644
--- a/node_modules/react-native-maps/src/specs/NativeComponentMarker.ts
+++ b/node_modules/react-native-maps/src/specs/NativeComponentMarker.ts
@@ -1,3 +1,4 @@
+// @ts-nocheck
 import type {HostComponent} from 'react-native';
 import type {
   ViewProps,

i upgraded to “react-native-maps”: “^1.23.8”, issue is still the same

Image

@salah-ghanim

@dannyhw After re-reading my message, I realize I may have sounded impatient — my apologies for that. I was concerned there might be some ‘under the radar’ work underway to fix React’s types directly (… or something else), which could have taken weeks or months to be merged, whereas there’s a better way to handle this.

Would having two versions of the lib (one for react 18 one for react 19) solve this issue

I think this is the way to go. From a semver standpoint you’d release react 19 support as 2.0 and then you could release parallel maintenance versions for react 18 as 1.23.9, 1.24.0 etc

or you could release React 19 support as 1.24.0 and the patches for the react 18 version as 1.23.9, 1.23.10, 1.23.11… etc

but strictly speaking, since it’s a breaking change, it should trigger a major version.

#5453 solves a different issue to this one from what I can tell. Looks like the function component type changed to allow for async components

// react 19
 interface FunctionComponent<P = {}> {
        (props: P): ReactNode | Promise<ReactNode>;
react 18
 interface FunctionComponent<P = {}> {
        (
            props: P,
            /**
             * @deprecated
             *
             * @see {@link https://legacy.reactjs.org/docs/legacy-context.html#referencing-context-in-lifecycle-methods React Docs}
             */
            deprecatedLegacyContext?: any,
        ): ReactNode;
        /**

This makes elementRef not allow componentType since its expecting a (props)=> reactnode type

    type ElementRef<
        C extends
            | ForwardRefExoticComponent<any>
            | { new(props: any): Component<any> }
            | ((props: any) => ReactNode)
            | keyof JSX.IntrinsicElements,
    > = ComponentRef<C>;

ForwardRefExoticComponent is basically a wrapper for ExoticComponent

  interface ExoticComponent<P = {}> {
        (props: P): ReactNode;
        readonly $$typeof: symbol;
    }

So you can see why the types don’t match from this, the thing is that elementRef is deprecated and componentRef is used instead in react19

complicating the issue is that react code gen specifically looks for element ref and will error on component ref

so you kinda need to use ExoticComponent instead of component type but it requires changing a lot of types or maybe (props:any)=>ReactNode

@salah-ghanim can perhaps answer that. Maybe its just gone under the radar but i had understood that there was some reason the typescript files were needed for the codegen to work correctly. Please be patient its likely that salah has a lot going on. I was just communicating what i had understood from my last conversation with him.

Much better than it was but I still get one too:

> tsc --noEmit

node_modules/react-native-maps/src/createFabricMap.tsx:48:49 - error TS2344: Type 'ComponentType<{}>' does not satisfy the constraint 'keyof IntrinsicElements | ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode)'.
  Type 'FunctionComponent<{}>' is not assignable to type 'keyof IntrinsicElements | ForwardRefExoticComponent<any> | (new (props: any) => Component<any, {}, any>) | ((props: any) => ReactNode)'.
    Property '$$typeof' is missing in type 'FunctionComponent<{}>' but required in type 'ForwardRefExoticComponent<any>'.

48       const fabricRef = useRef<React.ElementRef<typeof ViewComponent>>(null);
                                                   ~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:562:18
    562         readonly $$typeof: symbol;
                         ~~~~~~~~
    '$$typeof' is declared here.


Found 1 error in node_modules/react-native-maps/src/createFabricMap.tsx:48

 ELIFECYCLE  Command failed with exit code 2.

deps:

"typescript": "~5.8.3"
"react-native": "0.79.3",
"react-native-maps": "1.24.3",
"@types/react": "~19.0.10",
"expo": "~53.0.11",

Same story if I bump "@types/react": "~19.1.8", past expo recommended version.

Hey @salah-ghanim I managed to reproduce the error using a basic expo app. When generating a bare react-native app I don’t have the issue, I think it’s just a difference in base tsconfig but I didn’t investigate it yet:

https://github.com/ACHP/basic-expo-rnmaps-ts-leak

I think that by using this field in package.json we can just make it work.

  "main": "dist/src/index.js",
  "react-native": "src/index",
  "source": "src/index",
  "types": "dist/src/index.d.ts",

the problem is that even with the latest react native the codegen is using the old types so there isn’t a good way to just ‘update’. React native codegen needs updating to the new types imho which is out of this projects control. However I haven’t had a chance to investigate other workarounds.

@dannyhw thanks for the info.

the issue is that we need .ts files bundled because of codegen the specs need to be readable at runtime by Fabric, if I generate typed code d.ts then codegen breaks.

would having two versions of the lib (one for react 18 another for 19) solve this issue ?

I also get this error, its due to react 19 types I believe. If you replace with React.ComponentRef instead of element ref it resolves the type but seems to break codegen

maybe the example doesn’t get it since its missing the @types/react package

Also you cant stop typescript from returning type errors from libraries you import https://github.com/microsoft/TypeScript/issues/40426 https://github.com/microsoft/TypeScript/issues/47387

In my experience the best thing is to ship a bundled js output with generated .d.ts files that can be ignored by skipLibCheck

@dannyhw I’m curious — what are you referring to when you say “whilst a more complete solution is implemented”?

Maybe I’m missing something, but it feels like the correct solution to this problem is just to ship the .d.ts files, sources, and correct package.json configuration. And this solution has been known and ready to be merged even before the first workaround was merged so I don’t really understand what are we waiting for here

@elyobo the change that was made to skip the typechecks was a temporary workaround whilst a more complete solution is implemented, its already clear that its not ideal.

For me it is the updates of FunctionComponent in types/react that cause the issue. And I have created a discussion on DefinitelyTyped. I have tried to fix the issue, however I’m not sure if the Async Function Component want a ref prop. PR-DefinitelyTyped Anyone have an idea?