Skip to content

Commit 8699490

Browse files
authored
chore: Remove ReanimatedError and WorkletsError from global types (#8435)
## Summary This PR removes `ReanimatedError` and `WorkletsError` types from `privateGlobals.d.ts` type declarations. I decided to remove them as it was very confusing that TS wasn't complaining when these error constructors were called without importing them but the missing import resulted in the runtime crashes. ## Examples ### Before Allowed to use `ReanimatedError` without the necessary import. | Without import | With import | |-|-| | <img width="467" height="260" alt="Screenshot 2025-10-21 at 20 31 14" src="https://github.com/user-attachments/assets/040ec83a-a161-4bdb-be5f-50448b290946" /> | <img width="455" height="267" alt="Screenshot 2025-10-21 at 20 31 56" src="https://github.com/user-attachments/assets/d9e2cb8b-d740-46e9-bac0-311b08d4525f" /> | #### Without import in tests <img width="453" height="477" alt="Screenshot 2025-10-21 at 20 31 32" src="https://github.com/user-attachments/assets/62e813d4-eff4-4331-95a9-7bfb8274bf1f" /> ### After Properly shows that the `ReanimatedError` is not imported if there is no import. | Without import | With import | |-|-| | <img width="454" height="262" alt="Screenshot 2025-10-21 at 20 28 48" src="https://github.com/user-attachments/assets/6b48acb8-3a10-4f1f-8af5-80865106472e" /> | <img width="454" height="267" alt="Screenshot 2025-10-21 at 20 29 00" src="https://github.com/user-attachments/assets/fb3f2721-d670-46c4-8975-27e47e2e60a7" /> |
1 parent e358230 commit 8699490

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

packages/react-native-reanimated/src/common/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ function isWindowAvailable() {
1010
}
1111

1212
export const IS_ANDROID: boolean = Platform.OS === 'android';
13-
/** @knipIgnore */
1413
export const IS_IOS: boolean = Platform.OS === 'ios';
1514
export const IS_WEB: boolean = Platform.OS === 'web';
1615
export const IS_JEST: boolean = !!process.env.JEST_WORKER_ID;

packages/react-native-reanimated/src/common/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ function ReanimatedErrorConstructor(message: string): ReanimatedError {
1818
export function registerReanimatedError() {
1919
'worklet';
2020
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
21-
globalThis.ReanimatedError =
22-
ReanimatedErrorConstructor as IReanimatedErrorConstructor;
21+
(globalThis as Record<string, unknown>).ReanimatedError =
22+
ReanimatedErrorConstructor;
2323
}
2424
}
2525

2626
export const ReanimatedError =
2727
ReanimatedErrorConstructor as IReanimatedErrorConstructor;
2828

29-
export interface IReanimatedErrorConstructor extends Error {
29+
interface IReanimatedErrorConstructor extends Error {
3030
new (message?: string): ReanimatedError;
3131
(message?: string): ReanimatedError;
3232
readonly prototype: ReanimatedError;

packages/react-native-reanimated/src/privateGlobals.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
// This file works by accident - currently Builder Bob doesn't move `.d.ts` files to output types.
44
// If it ever breaks, we should address it so we'd not pollute the user's global namespace.
55

6-
import type {
7-
IReanimatedErrorConstructor,
8-
LoggerConfigInternal,
9-
} from './common';
6+
import type { LoggerConfigInternal } from './common';
107
import type {
118
MapperRegistry,
129
MeasuredDimensions,
@@ -82,5 +79,4 @@ declare global {
8279
* future.
8380
*/
8481
var __frameTimestamp: number | undefined;
85-
var ReanimatedError: IReanimatedErrorConstructor;
8682
}

packages/react-native-worklets/src/WorkletsError.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function WorkletsErrorConstructor(message?: string): WorkletsError {
1919
export function registerWorkletsError() {
2020
'worklet';
2121
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
22-
globalThis.WorkletsError =
23-
WorkletsErrorConstructor as IWorkletsErrorConstructor;
22+
(globalThis as Record<string, unknown>).WorkletsError =
23+
WorkletsErrorConstructor;
2424
}
2525
}
2626

@@ -29,7 +29,7 @@ export const WorkletsError =
2929

3030
export type WorkletsError = Error & { name: 'Worklets' }; // signed type
3131

32-
export interface IWorkletsErrorConstructor extends Error {
32+
interface IWorkletsErrorConstructor extends Error {
3333
new (message?: string): WorkletsError;
3434
(message?: string): WorkletsError;
3535
readonly prototype: WorkletsError;

packages/react-native-worklets/src/privateGlobals.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { callGuardDEV } from './callGuard';
66
import type { reportFatalRemoteError } from './errors';
77
import type { Queue } from './runLoop/workletRuntime/taskQueue';
88
import type { SynchronizableUnpacker } from './synchronizableUnpacker';
9-
import type { IWorkletsErrorConstructor } from './WorkletsError';
109
import type { WorkletsModuleProxy } from './WorkletsModule';
1110
import type { ValueUnpacker } from './workletTypes';
1211

@@ -70,7 +69,6 @@ declare global {
7069
worklet: SerializableRef<() => void>
7170
) => void;
7271
var _microtaskQueueFinalizers: (() => void)[];
73-
var WorkletsError: IWorkletsErrorConstructor;
7472
var _scheduleTimeoutCallback: (delay: number, handlerId: number) => void;
7573
var __runTimeoutCallback: (handlerId: number) => void;
7674
var __flushMicrotasks: () => void;

0 commit comments

Comments
 (0)