Skip to content

Commit

Permalink
Fix TS Type for measureLayout optional parameter
Browse files Browse the repository at this point in the history
Summary:
Encountered this, causing typechecking to fail on an example in the current RN documentation.

`onFail` is an optional parameter (see https://github.com/facebook/react/blob/8e2bde6f2751aa6335f3cef488c05c3ea08e074a/packages/react-native-renderer/src/ReactNativeTypes.js#L106), which is not optional in current TS types. Update the TS typings to match.

Note that "?" here is positioned to be a Flow optional parameter, instead of a maybe type. Which means it accepts undefined, but not null, matching the TS usage of "?" which always means possibly undefined (but never null, like a flow maybe type allows).

Changelog:
[General][Fixed] - Fix TS Type for measureLayout optional parameter

Reviewed By: lunaleaps

Differential Revision: D41775900

fbshipit-source-id: 8f53428b8077ec9139c7c1bbc60ed20f5fa9f7ea
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Dec 7, 2022
1 parent 0df2530 commit 5928144
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions types/public/ReactNativeTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ export interface NativeMethods {
* _Can also be called with a relativeNativeNodeHandle but is deprecated._
*/
measureLayout(
relativeToNativeComponentRef: HostComponent<unknown> | number,
relativeToNativeComponentRef:
| React.ElementRef<HostComponent<unknown>>
| number,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail: () => void /* currently unused */,
onFail?: () => void,
): void;

/**
Expand Down

0 comments on commit 5928144

Please sign in to comment.