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
This patch adds a
@ts-nocheckto 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
@salah-ghanim
i upgraded to “react-native-maps”: “^1.23.8”, issue is still the same
@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.
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
This makes elementRef not allow componentType since its expecting a
(props)=> reactnodetypeForwardRefExoticComponent is basically a wrapper for ExoticComponent
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:
deps:
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.jsonwe can just make it work.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.ComponentRefinstead of element ref it resolves the type but seems to break codegenmaybe 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
FunctionComponentin 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?