react-native-reanimated: Reanimated 2.5.0 breaks type checks
Description
Using the latest version, typescript checks are failing with a bunch of errors.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(2,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(3,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(4,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(5,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(6,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(7,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(10,22): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(11,22): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/animation/index.ts(12,21): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
node_modules/react-native-reanimated/src/reanimated2/core.ts(17,8): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
node_modules/react-native-reanimated/src/reanimated2/core.ts(21,12): error TS2339: Property '_setGlobalConsole' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/core.ts(23,10): error TS2339: Property '_setGlobalConsole' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/core.ts(102,8): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
node_modules/react-native-reanimated/src/reanimated2/core.ts(132,8): error TS2339: Property '_WORKLET' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/core.ts(133,8): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
node_modules/react-native-reanimated/src/reanimated2/core.ts(383,16): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
node_modules/react-native-reanimated/src/reanimated2/core.ts(384,14): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
node_modules/react-native-reanimated/src/reanimated2/core.ts(385,21): error TS2339: Property '_chronoNow' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/index.ts(17,10): error TS2339: Property '_frameTimestamp' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/index.ts(18,10): error TS2339: Property '_setGlobalConsole' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/index.ts(18,31): error TS7006: Parameter '_val' implicitly has an 'any' type.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/index.ts(21,10): error TS2339: Property '_measure' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/index.ts(34,10): error TS2339: Property '_scrollTo' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/index.ts(39,10): error TS2339: Property '_setGestureState' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/JSReanimated.ts(19,47): error TS2339: Property 'ReanimatedDataMock' does not exist on type 'typeof globalThis'.
node_modules/react-native-reanimated/src/reanimated2/js-reanimated/JSReanimated.ts(21,40): error TS2304: Cannot find name 'window'.
node_modules/react-native-reanimated/src/reanimated2/NativeReanimated/NativeReanimated.ts(14,16): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
node_modules/react-native-reanimated/src/reanimated2/NativeReanimated/NativeReanimated.ts(18,37): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
Expected behavior
Lib is working the same way as before.
Actual behavior & steps to reproduce
Type errors which are blocking me from using that newer release. Is should be quite well reproducable by using the latest version and a standard RN project. My tsconfig options are using the recommended values provided by expo and RN.
Snack or minimal code example
I am using the following tsconfig in my project:
{
"compilerOptions": {
/* Basic Options */
"target": "esnext",
"module": "commonjs",
"lib": ["es2017"],
"allowJs": true,
"jsx": "react-native",
"noEmit": true,
"isolatedModules": true,
/* Strict Type-Checking Options */
"strict": true,
/* Module Resolution Options */
"moduleResolution": "node",
"baseUrl": "./src",
"paths": { "@/*": ["./*"] },
"typeRoots": ["./@types", "./node_modules/@types"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"exclude": [
"node_modules", "babel.config.js", "metro.config.js", "jest.config.js"
]
}
Package versions
name | version |
---|---|
react-native | 0.67.4 |
react-native-reanimated | 2.5.0 |
NodeJS | 16.14.0 |
Xcode | 13.3 |
Java | 11 |
Gradle | |
expo | 44 |
Affected platforms
- Android
- iOS
- Web
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 42
- Comments: 19 (5 by maintainers)
@haveneersrobin thanks!
I hope this issue will be resolved soon by reanimated team
This issue seems to be still there in 2.8.0 (which is the version compatible with the latest expo@45).
See https://github.com/nearform/optic-expo/runs/7326068292?check_suite_focus=true#step:6:7
I have just released the new version 2.6.0 with the fix.
Reverting the type import/exports and augmenting some other types, seems to work for me. Here is the patch:
any update on this?
@haveneersrobin I used your solution, it works great for those types that need to be exported with the “type” qualifier.
I’m also running into several errors with the global declaration. i.e.
Error: node_modules/react-native-reanimated/src/reanimated2/core.ts:21:12 - error TS2339: Property '_setGlobalConsole' does not exist on type 'typeof globalThis'.
I checked the global.d.ts file and that method (and others that are erroring) are declared, not sure how to fix that one. It should be noted that OP’s error stack above lists those same global errors.
@enlightenedpie you should not create a new issue if it is the same as what is mentioned here 😃 Just so we have it all in one place. Also, you have just created a ‘solution’, that’s not what the issue tracker is for.
On the other hand: are you sure you’ve correctly applied my patch, because that normally fixes all the problems you’ve mentioned. Deleting the line
import('./src/reanimated2/globals');
is what fixes thetypeof globalThis
issues.You can use reanimated 3
Any way someone could point me in the correct direction.
It doesn’t appear to be able to find any of the items which are listed as global at the top of core.ts when running
tsc
/* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp, _setGlobalConsole */
I have gone over the patch several times and I get these errors after applying it.