software-mansion / react-native-screens

Native navigation primitives for your React Native app.
https://docs.swmansion.com/react-native-screens/
MIT License
3.05k stars 516 forks source link

Typescript error after update to latest #2294

Closed Cancercookie closed 3 weeks ago

Cancercookie commented 2 months ago

Description

I am receiving the following errors with tsc after upgrading to the latest version of screen and all the @react-navigation packages.


node_modules/react-native-screens/src/native-stack/types.tsx:63:3 - error TS2344: Type 'StackNavigationState<ParamList>' does not satisfy the constraint 'string | undefined'.

63   StackNavigationState<ParamList>,
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/react-native-screens/src/native-stack/types.tsx:488:3 - error TS2314: Generic type 'DefaultNavigatorOptions' requires 4 type argument(s).

488   DefaultNavigatorOptions<NativeStackNavigationOptions> &
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/react-native-screens/src/native-stack/types.tsx:492:37 - error TS2314: Generic type 'Descriptor' requires 3 type argument(s).

492 export type NativeStackDescriptor = Descriptor<
                                        ~~~~~~~~~~~
493   ParamListBase,
    ~~~~~~~~~~~~~~~~
... 
496   NativeStackNavigationOptions
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
497 >;
    ~

my packages that could be related to this issue:

"@react-navigation/drawer": "^6.7.0",
"@react-navigation/native": "^6.1.0",
"@react-navigation/native-stack": "^6.11.0",
"@react-navigation/stack": "^6.4.0",
"react-native-screens": "3.34.0",
"typescript": "~5.0.0"
"react-native": "0.73.6"

If I stop responding I may be on vacation, I'll resume my activities in 2 weeks.

Steps to reproduce

Upgrade to latest with said dependencies

Snack or a link to a repository

my repo is private sorry

Screens version

3.34.0

React Native version

0.73.6

Platforms

Android, iOS

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

github-actions[bot] commented 2 months ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

alduzy commented 2 months ago

@Cancercookie That's unusual, have you tried removing the node_modules and installing the dependencies again or restarting the TS server?

Btw. the 3.34.0 version should be used with react-native 0.75.x (see https://github.com/software-mansion/react-native-screens#support-for-fabric). Let me know if the problem still persists

Cancercookie commented 2 months ago

I've tried node_modules and restart. But I guess the main issue is using this version with 0.73.x, when I saw compatibility with 0.75+ in the changelog I also assumed retrocompatibility, I didn't check the table in README. I'll revert to a previous version and report back. Thanks.

alduzy commented 2 months ago

@Cancercookie You're right the compatibility rules apply to fabric and not necessarily to paper. Anyway, let me know if downgrading helped.

Cancercookie commented 1 month ago

@alduzy Sorry for being this late, I tried downgrading from 3.34.0 to 3.30.0 decrementally but nothing. If I revert back to 3.29.0 the error goes away.

alduzy commented 1 month ago

@Cancercookie Can you add a minimal reproduction?

Cancercookie commented 1 month ago

https://github.com/Cancercookie/screen-repro

alduzy commented 1 month ago

Hi @Cancercookie thanks for submitting the repro, what steps do I have to perform in order to get the error? I tried yarn tsc but could not reproduce it. You can also check if using yarn tsc --skipLibCheck helps in your case. Make sure you restart the ts server.

Cancercookie commented 3 weeks ago

https://github.com/Cancercookie/screen-repro I updated the repro.

I failed to notice that because I was not referencing a react-native-screens type directly in my project the error was not showing in tsc .

Changing the imports from import { SearchBarCommands } from "react-native-screens/src/types" to import { SearchBarCommands } from "react-native-screens" solved the issue in my project.

alduzy commented 3 weeks ago

@Cancercookie Good to hear that you were able to resolve the issue!