Skip to content

Commit 07b94a5

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Declare type parameter bounds that type arguments rely on
Summary: Flow will check type arguments against the bounds of their type parameters where a type application is written, including inside generic definitions. These definitions pass a type parameter to a type whose parameter is bounded without declaring the bound themselves: - `TextInputNativeCommands<T>` passes `T` to `React.ElementRef`, which needs a React element type. - `patchedDeref<T>` passes `T` to `WeakRef`, which needs a `WeakKey`. - The `Omit` helper in `ProgressBarAndroid` uses `keyof T` with an unbounded `T`. - `ComponentProps` in `createAnimatedComponent` passes an unbounded `infer Props` to `React.ComponentType`, which needs an object type. This declares the bounds; it changes no runtime code. Changelog: [Internal] Differential Revision: D132221254
1 parent 6144835 commit 07b94a5

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎packages/react-native/Libraries/Animated/createAnimatedComponent.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Builtin = (
3333
...rest: ReadonlyArray<empty>
3434
) => unknown | Date | Error | RegExp;
3535
type ComponentProps<T> =
36-
T extends React.ComponentType<infer Props> ? Props : empty;
36+
T extends React.ComponentType<infer Props extends {...}> ? Props : empty;
3737

3838
export type WithAnimatedValue<out T> = T extends Builtin | Nullable
3939
? T

‎packages/react-native/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export type {ProgressBarAndroidProps};
2323
// of ProgressBarAndroidProps. TS's Omit does not distribute over unions, so
2424
// we define our own version which does. This does not affect Flow.
2525
// $FlowExpectedError[unclear-type]
26-
type Omit<T, K> = T extends any ? Pick<T, Exclude<keyof T, K>> : T;
26+
type Omit<T extends interface {}, K> = T extends any
27+
? Pick<T, Exclude<keyof T, K>>
28+
: T;
2729

2830
/**
2931
* ProgressBarAndroid has been extracted from react-native core and will be removed in a future release.

‎packages/react-native/Libraries/Components/TextInput/TextInputNativeCommands.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {Int32} from '../../Types/CodegenTypes';
1212

1313
import * as React from 'react';
1414

15-
export interface TextInputNativeCommands<T> {
15+
export interface TextInputNativeCommands<T extends React.ElementType> {
1616
readonly focus: (viewRef: React.ElementRef<T>) => void;
1717
readonly blur: (viewRef: React.ElementRef<T>) => void;
1818
readonly setTextAndSelection: (

‎packages/react-native/ReactNativeApi.d.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<700a3fc87e57596903b6cf32a165eeb9>>
7+
* @generated SignedSource<<5fb88c816966453fdc33d4cf9c2caa29>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -1768,7 +1768,7 @@ declare type ColorSchemeName = "dark" | "light"
17681768
declare type ColorSchemeOverride = "auto" | "dark" | "light" | "unspecified"
17691769
declare type ColorValue = ____ColorValue_Internal
17701770
declare type ComponentProps<T> =
1771-
T extends React.ComponentType<infer Props> ? Props : never
1771+
T extends React.ComponentType<infer Props extends {}> ? Props : never
17721772
declare type ComponentProvider = () => React.ComponentType<any>
17731773
declare type ComponentProviderInstrumentationHook = (
17741774
component_: ComponentProvider,
@@ -3350,7 +3350,9 @@ declare type NonAnimatedProps =
33503350
| "scrollViewRef"
33513351
| "testID"
33523352
declare type Nullable = null | void
3353-
declare type Omit_2<T, K> = T extends any ? Pick<T, Exclude<keyof T, K>> : T
3353+
declare type Omit_2<T extends {}, K> = T extends any
3354+
? Pick<T, Exclude<keyof T, K>>
3355+
: T
33543356
declare type OnAnimationDidEndCallback = () => void
33553357
declare type OnAnimationDidFailCallback = () => void
33563358
declare type OpaqueColorValue = NativeColorValue
@@ -6039,7 +6041,7 @@ export {
60396041
PressableProps, // 5f06b483
60406042
PressableStateCallbackType, // f83728cd
60416043
ProcessedColorValue, // 33f74304
6042-
ProgressBarAndroid, // 7d199258
6044+
ProgressBarAndroid, // 00867749
60436045
ProgressBarAndroidInstance, // e25bcc95
60446046
ProgressBarAndroidProps, // 07593242
60456047
PublicRootInstance, // 8040afd7

‎private/react-native-fantom/runtime/patchWeakRef.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export default function patchWeakRef(): void {
2828
const originalDeref = WeakRef.prototype.deref;
2929

3030
// $FlowExpectedError[cannot-write]
31-
WeakRef.prototype.deref = function patchedDeref<T>(this: WeakRef<T>): T {
31+
WeakRef.prototype.deref = function patchedDeref<T extends WeakKey>(
32+
this: WeakRef<T>,
33+
): T {
3234
// Lazily require the module to avoid loading it before the test logic.
3335
const Fantom = require('@react-native/fantom');
3436

0 commit comments

Comments
 (0)