diff --git a/packages/react-native/Libraries/Animated/AnimatedEvent.js b/packages/react-native/Libraries/Animated/AnimatedEvent.js index 866e9bdb20d7..4704a87e4216 100644 --- a/packages/react-native/Libraries/Animated/AnimatedEvent.js +++ b/packages/react-native/Libraries/Animated/AnimatedEvent.js @@ -197,7 +197,7 @@ export class AnimatedEvent { this._attachedEvent && this._attachedEvent.detach(); } - __getHandler(): any | ((...args: any) => void) { + __getHandler(): (...args: any) => void { if (this.__isNative) { if (__DEV__) { let validatedMapping = false; diff --git a/packages/react-native/Libraries/Animated/AnimatedImplementation.js b/packages/react-native/Libraries/Animated/AnimatedImplementation.js index 4a9d76a4806a..7fc01bb27249 100644 --- a/packages/react-native/Libraries/Animated/AnimatedImplementation.js +++ b/packages/react-native/Libraries/Animated/AnimatedImplementation.js @@ -576,10 +576,14 @@ function unforkEventImpl( } } -const eventImpl = function ( +// NOTE: With `useNativeDriver: true` this returns an `AnimatedEvent` instance +// rather than a callable handler. That object is only ever meant to be handed +// straight back to an animated component's event prop, so the declared type +// describes the handler shape both branches are consumed as. +const eventImpl: ( argMapping: ReadonlyArray, config: EventConfig, -): any { +) => (...args: Array) => void = function (argMapping, config): any { const animatedEvent = new AnimatedEvent(argMapping, config); if (animatedEvent.__isNative) { return animatedEvent; diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index a04517cbd5a0..0b667e3cc6e2 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<44990574a74bcc122718d4f6142db8cd>> + * @generated SignedSource<<5335b26453a7d4d5bb9b7d54ded6218f>> * * This file was generated by scripts/js-api/build-types/index.js. */ @@ -232,7 +232,7 @@ declare const event: typeof $$AnimatedImplementation.event declare const eventImpl: ( argMapping: ReadonlyArray, config: EventConfig, -) => any +) => (...args: Array) => void declare const findNodeHandle: typeof $$ReactFabric.findNodeHandle declare const flatten: typeof $$flattenStyle declare const forkEvent: typeof $$AnimatedImplementation.forkEvent diff --git a/packages/react-native/src/private/animated/__tests__/AnimatedNative-test.js b/packages/react-native/src/private/animated/__tests__/AnimatedNative-test.js index 667afdd9fb77..0141d70dd6cc 100644 --- a/packages/react-native/src/private/animated/__tests__/AnimatedNative-test.js +++ b/packages/react-native/src/private/animated/__tests__/AnimatedNative-test.js @@ -369,7 +369,7 @@ describe('Native Animated', () => { const value = new Animated.Value(0); value.__makeNative(); const listener = jest.fn(); - const event = Animated.event([{nativeEvent: {foo: value}}], { + const event = new Animated.Event([{nativeEvent: {foo: value}}], { useNativeDriver: true, listener, });