diff --git a/package.json b/package.json index eee23c642e54..bfcdb811996d 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "test-release-local": "node ./scripts/release-testing/test-release-local.js", "test-ios": "./scripts/objc-test.sh test", "test-typescript-legacy": "tsc -p packages/react-native/__typetests__/tsconfig.legacy.json", - "test-generated-typescript": "tsc -p packages/react-native/__typetests__/tsconfig.json", + "test-generated-typescript": "tsc -p packages/react-native/__typetests__/tsconfig.json && tsc -p packages/react-native/__typetests__/tsconfig.strict.json", "test": "jest", "fantom": "./scripts/fantom.sh", "fantom-cli": "./scripts/fantom-cli.sh", diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js index 604ec5fcd5ff..e34a266632d8 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js @@ -27,7 +27,7 @@ import invariant from 'invariant'; export type AnimatedPropsAllowlist = Readonly<{ style?: ?AnimatedStyleAllowlist, - [key: string]: true | AnimatedStyleAllowlist, + [key: string]: ?(true | AnimatedStyleAllowlist), }>; type TargetView = { diff --git a/packages/react-native/Libraries/Lists/VirtualizedList.js b/packages/react-native/Libraries/Lists/VirtualizedList.js index b095a35ffafd..5e1a16b0d4ae 100644 --- a/packages/react-native/Libraries/Lists/VirtualizedList.js +++ b/packages/react-native/Libraries/Lists/VirtualizedList.js @@ -11,15 +11,13 @@ 'use strict'; import VirtualizedLists from '@react-native/virtualized-lists'; -import * as React from 'react'; type VirtualizedListType = typeof VirtualizedLists.VirtualizedList; const VirtualizedListComponent: VirtualizedListType = VirtualizedLists.VirtualizedList; -export type VirtualizedListInstance = React.ElementRef; - export type { + VirtualizedListInstance, ListRenderItemInfo, ListRenderItem, ListViewToken, diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index b5127f242a2f..386a9257e418 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<<08c63097104ab811ba2be19ded117820>> + * @generated SignedSource<> * * This file was generated by scripts/js-api/build-types/index.js. */ @@ -4105,7 +4105,7 @@ declare class ReadOnlyNode_default extends EventTarget_default { get parentElement(): null | ReadOnlyElement_default get parentNode(): null | ReadOnlyNode_default get previousSibling(): null | ReadOnlyNode_default - get textContent(): string + get textContent(): null | string } declare class ReadOnlyText_default extends ReadOnlyCharacterData_default { get nodeName(): string @@ -5769,7 +5769,7 @@ declare function VirtualizedListContextResetter($$PARAM_0$$: { }): React.ReactNode declare type VirtualizedListContextResetterT = typeof VirtualizedListContextResetter -declare type VirtualizedListInstance = React.ComponentRef +declare type VirtualizedListInstance = VirtualizedList_default declare type VirtualizedListProps = ScrollViewProps & RequiredVirtualizedListProps & OptionalVirtualizedListProps @@ -5884,31 +5884,31 @@ declare type WrapperComponentProvider = ( appKey?: string, ) => React.ComponentType export { - AccessibilityActionEvent, // cb5fb190 + AccessibilityActionEvent, // f7a22848 AccessibilityActionInfo, // c94545a7 - AccessibilityInfo, // 8d4b8bc6 + AccessibilityInfo, // 727f4628 AccessibilityProps, // 95dbb1d8 AccessibilityRole, // f2f2e066 AccessibilityState, // b0c2b3f7 AccessibilityValue, // cf8bcb74 ActionSheetIOS, // b558559e ActionSheetIOSOptions, // 1756eb5a - ActivityIndicator, // b7793e9b - ActivityIndicatorInstance, // 69299e35 - ActivityIndicatorProps, // 0489dc5e + ActivityIndicator, // 5dff58cf + ActivityIndicatorInstance, // af9f87f1 + ActivityIndicatorProps, // bc68b821 Alert, // a398a509 AlertButton, // bf1a3b60 AlertButtonStyle, // ec9fb242 AlertOptions, // 8a116d2a AlertType, // 5ab91217 AndroidKeyboardEvent, // e03becc8 - Animated, // ba13f2de - AnimatedFlatList, // 074a4512 - AnimatedImage, // 7efc2e4d - AnimatedScrollView, // 338d60e0 - AnimatedSectionList, // 78177f8d - AnimatedText, // c068e60d - AnimatedView, // 0f3aeb93 + Animated, // ff6c7ccc + AnimatedFlatList, // f446c982 + AnimatedImage, // c1b8caf2 + AnimatedScrollView, // d469452e + AnimatedSectionList, // b830ce59 + AnimatedText, // ce1c97c3 + AnimatedView, // 087c3510 AppConfig, // 80afc5fa AppRegistry, // 2fad6d0e AppState, // db34d225 @@ -5920,12 +5920,12 @@ export { AutoCapitalize, // c0e857a0 BackHandler, // 29f7039a BackPressEventName, // 4620fb76 - BlurEvent, // 00c596e2 + BlurEvent, // 44e53aa8 BoxShadowValue, // b679703f - Button, // 2ec045d1 - ButtonInstance, // 3bfc75a3 - ButtonProps, // 2fe658e4 - CodegenTypes, // d0052fd4 + Button, // 2b1a7dba + ButtonInstance, // 28b42c36 + ButtonProps, // a1671cb9 + CodegenTypes, // 033a5b4e ColorSchemeName, // 6615edd6 ColorValue, // 98989a8f ComponentProvider, // bf78f91b @@ -5941,10 +5941,10 @@ export { DimensionsPayload, // 653bc26c DisplayMetrics, // 1dc35cef DisplayMetricsAndroid, // 872e62eb - DrawerLayoutAndroid, // 65e3d444 + DrawerLayoutAndroid, // 220fa825 DrawerLayoutAndroidInstance, // aa243cbf - DrawerLayoutAndroidProps, // 013b18ba - DrawerSlideEvent, // aa703fa0 + DrawerLayoutAndroidProps, // 70505ad0 + DrawerSlideEvent, // f0815db2 DropShadowValue, // e9df2606 DynamicColorIOS, // d96c228c DynamicColorIOSTuple, // 023ce58e @@ -5959,31 +5959,31 @@ export { EventSubscription, // b8d084aa ExtendedExceptionData, // 5a6ccf5a FilterFunction, // bf24c0e3 - FlatList, // 733aeed0 - FlatListInstance, // e268301f - FlatListProps, // b23f662a - FocusEvent, // f7d67f9b + FlatList, // 0e585aac + FlatListInstance, // c321b73e + FlatListProps, // bc4c54fa + FocusEvent, // 7547e0c7 FontVariant, // 7c7558bb - GestureResponderEvent, // cbf6abac - GestureResponderHandlers, // 75220e0c - HostComponent, // 6ae8255a - HostInstance, // 038429fb + GestureResponderEvent, // 3f2a1a59 + GestureResponderHandlers, // fc89bc11 + HostComponent, // 818990e7 + HostInstance, // c0ac24f8 I18nManager, // f9870e00 IEventEmitter, // fbef6131 IOSKeyboardEvent, // e67bfe3a IgnorePattern, // ec6f6ece - Image, // 9955197c - ImageBackground, // 5725330b - ImageBackgroundInstance, // b89488b9 - ImageBackgroundProps, // 69b7bff8 - ImageErrorEvent, // e2926c20 - ImageInstance, // 46f8deb7 - ImageLoadEvent, // 9b52ad36 - ImageProgressEventIOS, // a97c3831 - ImageProps, // dbe27897 + Image, // f1761019 + ImageBackground, // 6f4c6cc4 + ImageBackgroundInstance, // 55ae0e9d + ImageBackgroundProps, // 16908e2f + ImageErrorEvent, // dd3b2e33 + ImageInstance, // ef4ec54b + ImageLoadEvent, // 960cd079 + ImageProgressEventIOS, // 62f00d39 + ImageProps, // dfd361f4 ImagePropsAndroid, // 283349a4 - ImagePropsBase, // 5cc32b8d - ImagePropsIOS, // 4f29f905 + ImagePropsBase, // 158b06e0 + ImagePropsIOS, // 5d60e52e ImageRequireSource, // 681d683b ImageResizeMode, // d51106e2 ImageResolvedAssetSource, // f3060931 @@ -5996,13 +5996,13 @@ export { InputAccessoryViewProps, // 01e6ca03 InputModeOptions, // 4e8581b9 Insets, // e7fe432a - KeyDownEvent, // ccd5ec9d + KeyDownEvent, // eaa7f1c1 KeyEvent, // 20fa4267 - KeyUpEvent, // e45aac1c + KeyUpEvent, // f5fa3520 Keyboard, // a26f7bd4 - KeyboardAvoidingView, // ec903233 - KeyboardAvoidingViewInstance, // 9512f9c1 - KeyboardAvoidingViewProps, // 13f6fa24 + KeyboardAvoidingView, // 62fc0d8c + KeyboardAvoidingViewInstance, // b4e47c7c + KeyboardAvoidingViewProps, // 8d78d000 KeyboardEvent, // c3f895d4 KeyboardEventEasing, // af4091c8 KeyboardEventName, // 59299ad6 @@ -6015,7 +6015,7 @@ export { LayoutAnimationProperty, // 52995f01 LayoutAnimationType, // 2da0a29b LayoutAnimationTypes, // 081b3bde - LayoutChangeEvent, // c06f2dbf + LayoutChangeEvent, // bc3331b5 LayoutConformanceProps, // 055f03b8 LayoutRectangle, // 6601b294 Linking, // 73c2b170 @@ -6027,33 +6027,33 @@ export { MeasureInWindowOnSuccessCallback, // a285f598 MeasureLayoutOnSuccessCallback, // 3592502a MeasureOnSuccessCallback, // 82824e59 - Modal, // 7910201f - ModalBaseProps, // 18ba4525 - ModalInstance, // c47ff608 - ModalProps, // 9d78b278 + Modal, // 6eab072e + ModalBaseProps, // 5d18edee + ModalInstance, // 99444d96 + ModalProps, // 0fb1fcb9 ModalPropsAndroid, // 515fb173 - ModalPropsIOS, // 7943cbd7 - ModeChangeEvent, // 9e9a28c4 - MouseEvent, // 420b6a25 + ModalPropsIOS, // 9546bd5d + ModeChangeEvent, // 1d28d526 + MouseEvent, // 807b8ee9 NativeAppEventEmitter, // 08d4c47d NativeColorValue, // d2094c29 - NativeComponentRegistry, // 94e3523f + NativeComponentRegistry, // 4770d61a NativeEventEmitter, // 27f97c1a NativeEventSubscription, // de3942e7 NativeModules, // 4597cd36 - NativeMouseEvent, // c615eaf0 - NativePointerEvent, // e52efcf2 + NativeMouseEvent, // 97fbb747 + NativePointerEvent, // 9b49ff2a NativeScrollEvent, // caad7f53 - NativeSyntheticEvent, // 8602b1b6 + NativeSyntheticEvent, // c8f0ef77 NativeTouchEvent, // 59b676df NativeUIEvent, // 44ac26ac Networking, // 65945401 OpaqueColorValue, // 25f3fa5b PackagerAsset, // d1c88cf4 - PanResponder, // 4751fd91 - PanResponderCallbacks, // 954fbae3 + PanResponder, // 9d3f5073 + PanResponderCallbacks, // 2ebfe34d PanResponderGestureState, // 54baf558 - PanResponderInstance, // 70913564 + PanResponderInstance, // c76430ed Permission, // 08f1c82f PermissionStatus, // 4b7de97b PermissionsAndroid, // 8a0bc8d8 @@ -6063,32 +6063,32 @@ export { PlatformOSType, // 0a17561e PlatformSelectSpec, // 09ed7758 PointValue, // 69db075f - PointerEvent, // a3d953b4 - PressabilityConfig, // 5a09717f - PressabilityEventHandlers, // 4ffc75dd - Pressable, // 08640c93 + PointerEvent, // 736adf81 + PressabilityConfig, // af4ede97 + PressabilityEventHandlers, // 497afe11 + Pressable, // deb5e059 PressableAndroidRippleConfig, // ee32eaca - PressableInstance, // 4f7bc23d - PressableProps, // bd3d6042 + PressableInstance, // f65bde4b + PressableProps, // 711e9283 PressableStateCallbackType, // f83728cd ProcessedColorValue, // 33f74304 - ProgressBarAndroid, // d5f7ad5d - ProgressBarAndroidInstance, // e049fddf - ProgressBarAndroidProps, // 4b8826f6 + ProgressBarAndroid, // bd5387e6 + ProgressBarAndroidInstance, // b1154dbb + ProgressBarAndroidProps, // 25661bd4 PublicRootInstance, // 8040afd7 - PublicTextInstance, // ab85b323 + PublicTextInstance, // 1d09c6ee PushNotificationEventName, // 84e7e150 PushNotificationIOS, // b4d1fe78 PushNotificationPermissions, // c2e7ae4f Rationale, // 5df1b1c1 ReactNativeVersion, // abd76827 - RefreshControl, // 48abafa2 - RefreshControlInstance, // b79668ce - RefreshControlProps, // 511625b4 + RefreshControl, // eb1ba766 + RefreshControlInstance, // 6211c7a7 + RefreshControlProps, // e04f5969 RefreshControlPropsAndroid, // 8ac931ca RefreshControlPropsIOS, // 72a36381 Registry, // e7beb42e - ResponderSyntheticEvent, // 0b152ee2 + ResponderSyntheticEvent, // dcc8e768 ReturnKeyTypeOptions, // afd47ba3 Role, // af7b889d RootTag, // 3cd10504 @@ -6097,25 +6097,25 @@ export { Runnable, // 557d13d9 Runnables, // 75114853 SafeAreaInsets, // 64d7a605 - SafeAreaInsetsChangeEvent, // ecf5a1e0 - SafeAreaView, // fa1a071b - SafeAreaViewInstance, // a873bd17 + SafeAreaInsetsChangeEvent, // 72778b18 + SafeAreaView, // f588f262 + SafeAreaViewInstance, // b24dd01c ScaledSize, // 07e417c7 - ScrollEvent, // 8dfaa310 - ScrollResponderType, // d9b5b457 + ScrollEvent, // 1d1fcc5e + ScrollResponderType, // 54145c71 ScrollToLocationParamsType, // d7ecdad1 - ScrollView, // d57bd638 - ScrollViewImperativeMethods, // eca21efb - ScrollViewInstance, // 1bb729e1 - ScrollViewProps, // 3a8aadd4 + ScrollView, // 4a7d7619 + ScrollViewImperativeMethods, // f484ef01 + ScrollViewInstance, // 9c204b9e + ScrollViewProps, // 8ebb6123 ScrollViewPropsAndroid, // 02f3df2e - ScrollViewPropsIOS, // e93686bd + ScrollViewPropsIOS, // a8942e93 ScrollViewScrollToOptions, // 3313411e SectionBase, // 9f13db00 - SectionList, // de2387ef + SectionList, // 40441ed5 SectionListData, // 1a4de01a - SectionListInstance, // 18cb42a2 - SectionListProps, // 0b896ccd + SectionListInstance, // 4447171f + SectionListProps, // c8d27174 SectionListRenderItem, // 715b2086 SectionListRenderItemInfo, // 4a48a922 Separators, // 6a45f7e3 @@ -6135,79 +6135,79 @@ export { StyleProp, // fa0e9b4a StyleSheet, // c4e999f5 SubmitBehavior, // c4ddf490 - Switch, // 742d84cf - SwitchChangeEvent, // 459b3e36 - SwitchInstance, // f17ba6e8 - SwitchProps, // f9d89fff + Switch, // d7e70790 + SwitchChangeEvent, // a34c65e2 + SwitchInstance, // c833fbb4 + SwitchProps, // 338a857e Systrace, // 2a0a0871 TVViewPropsIOS, // 1c612e4e TargetedEvent, // 16e98910 TaskProvider, // 266dedf2 - Text, // e5ca453d + Text, // 12d28e7d TextContentType, // 239b3ecc - TextInput, // 2d145d55 + TextInput, // ee868d90 TextInputAndroidProps, // 9ebbc103 - TextInputBlurEvent, // ac0d8a35 - TextInputChangeEvent, // 4123dc4d - TextInputContentSizeChangeEvent, // c731debd - TextInputEndEditingEvent, // af28a868 - TextInputFocusEvent, // 1cadd01c + TextInputBlurEvent, // d910a669 + TextInputChangeEvent, // aa38a9a8 + TextInputContentSizeChangeEvent, // 8ebbd9fd + TextInputEndEditingEvent, // c8ebe659 + TextInputFocusEvent, // 88f79567 TextInputIOSProps, // fb3c9327 - TextInputInstance, // e5cb59ab - TextInputKeyPressEvent, // 5b603a00 - TextInputProps, // e22d3199 - TextInputSelectionChangeEvent, // 817bea8a - TextInputSubmitEditingEvent, // 260f6e41 - TextInstance, // c927e793 - TextLayoutEvent, // e9765128 - TextProps, // 8c6d9a0b + TextInputInstance, // 3d26c439 + TextInputKeyPressEvent, // 807a5806 + TextInputProps, // 13fe2a48 + TextInputSelectionChangeEvent, // 6c0b227b + TextInputSubmitEditingEvent, // 9bca12d8 + TextInstance, // 997afe03 + TextLayoutEvent, // 253cb7d8 + TextProps, // 2047b90b TextStyle, // 3273abd5 ToastAndroid, // 88a8969a - TouchableHighlight, // cf3d9aa6 - TouchableHighlightInstance, // 7fb6781a - TouchableHighlightProps, // 9946a487 - TouchableNativeFeedback, // 57e2aa1a - TouchableNativeFeedbackInstance, // 49aa3150 - TouchableNativeFeedbackProps, // efc2e1d1 - TouchableOpacity, // 1432d33f - TouchableOpacityInstance, // dca89710 - TouchableOpacityProps, // 8622c6f0 - TouchableWithoutFeedback, // 50494783 - TouchableWithoutFeedbackProps, // 64c9e4df + TouchableHighlight, // 979fef8a + TouchableHighlightInstance, // a9604e7a + TouchableHighlightProps, // b8c49a73 + TouchableNativeFeedback, // 102fd55a + TouchableNativeFeedbackInstance, // 7f7eb086 + TouchableNativeFeedbackProps, // 4c3439d5 + TouchableOpacity, // 62aeea16 + TouchableOpacityInstance, // 4f409247 + TouchableOpacityProps, // fb35f884 + TouchableWithoutFeedback, // 1a4d12bf + TouchableWithoutFeedbackProps, // b572e781 TransformsStyle, // 65e70f18 TurboModule, // dfe29706 TurboModuleRegistry, // 4ace6db2 UIManager, // 6a18fc05 UTFSequence, // ad625158 Vibration, // 31e4bbf8 - View, // 7986403b - ViewInstance, // 9caf25c4 - ViewProps, // 82e8825a - ViewPropsAndroid, // dada44cc + View, // a396f1a8 + ViewInstance, // bb3d9567 + ViewProps, // cf07e54e + ViewPropsAndroid, // 57a3d58d ViewPropsIOS, // 58ee19bf ViewStyle, // 71dee3fb ViewabilityConfig, // eb3f7ed8 ViewabilityConfigCallbackPair, // bdd0788c VirtualViewMode, // 6be59722 VirtualizedList, // 68c7345e - VirtualizedListInstance, // 423ee7c0 - VirtualizedListProps, // 372f7a9e + VirtualizedListInstance, // 773a506c + VirtualizedListProps, // a8fcc487 VirtualizedSectionList, // 9fd9cd61 VirtualizedSectionListInstance, // 12b706d5 - VirtualizedSectionListProps, // 0140c701 + VirtualizedSectionListProps, // 090380e8 WrapperComponentProvider, // 6ce47ba4 codegenNativeCommands, // 322f3f4e - codegenNativeComponent, // 162426af + codegenNativeComponent, // cf5807e2 findNodeHandle, // 93f80214 processColor, // 6e877698 registerCallableModule, // 55bda579 - requireNativeComponent, // 27104937 + requireNativeComponent, // 82bebd6d useAnimatedColor, // 1faf88ce useAnimatedValue, // dc9d6f5c useAnimatedValueXY, // dc9057ea useAppState, // 9338748a useColorScheme, // d585efdb - usePressability, // 3e2d90f3 + usePressability, // af892998 useVerticalBarEdgeIOS, // a0670270 useWindowDimensions, // bb4b683f } diff --git a/packages/react-native/__typetests__/strict-lib-check.ts b/packages/react-native/__typetests__/strict-lib-check.ts new file mode 100644 index 000000000000..cf6ae2d5c71c --- /dev/null +++ b/packages/react-native/__typetests__/strict-lib-check.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +// Entry point for `tsconfig.strict.json`. Importing the package is enough: +// with `skipLibCheck` off, TypeScript checks every declaration file it reaches. +import 'react-native'; diff --git a/packages/react-native/__typetests__/tsconfig.strict.json b/packages/react-native/__typetests__/tsconfig.strict.json new file mode 100644 index 000000000000..95e0504c372f --- /dev/null +++ b/packages/react-native/__typetests__/tsconfig.strict.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + // Strict variant: Type checks the generated declarations themselves the way + // an app with `"strict": true` and `"skipLibCheck": false` does. + "extends": "./tsconfig.json", + "compilerOptions": { + "strict": true, + "skipLibCheck": false + }, + "include": [], + "files": ["strict-lib-check.ts"] +} diff --git a/packages/react-native/src/private/webapis/dom/nodes/ReactNativeDocument.js b/packages/react-native/src/private/webapis/dom/nodes/ReactNativeDocument.js index 70cd2ff59fe3..677e95c5fd59 100644 --- a/packages/react-native/src/private/webapis/dom/nodes/ReactNativeDocument.js +++ b/packages/react-native/src/private/webapis/dom/nodes/ReactNativeDocument.js @@ -80,7 +80,6 @@ export default class ReactNativeDocument extends ReadOnlyNode { return null; } - // $FlowExpectedError[incompatible-type] This is defined as returning string in Node, but it's actually null in Document. // $FlowFixMe[unsafe-getters-setters] get textContent(): null { return null; diff --git a/packages/react-native/src/private/webapis/dom/nodes/ReadOnlyNode.js b/packages/react-native/src/private/webapis/dom/nodes/ReadOnlyNode.js index 395d040dbf33..96827736c6ad 100644 --- a/packages/react-native/src/private/webapis/dom/nodes/ReadOnlyNode.js +++ b/packages/react-native/src/private/webapis/dom/nodes/ReadOnlyNode.js @@ -192,7 +192,7 @@ class ReadOnlyNode extends EventTarget { * @abstract */ // $FlowFixMe[unsafe-getters-setters] - get textContent(): string { + get textContent(): string | null { throw new TypeError( '`textContent` is abstract and must be implemented in a subclass of `ReadOnlyNode`', ); diff --git a/packages/virtualized-lists/index.js b/packages/virtualized-lists/index.js index 9bcac9976b7f..d364e0bb783c 100644 --- a/packages/virtualized-lists/index.js +++ b/packages/virtualized-lists/index.js @@ -12,6 +12,7 @@ import typeof FillRateHelperT from './Lists/FillRateHelper'; import typeof ViewabilityHelperT from './Lists/ViewabilityHelper'; +import type VirtualizedListInstanceT from './Lists/VirtualizedList'; import typeof VirtualizedListT from './Lists/VirtualizedList'; import type {AnyVirtualizedSectionList as AnyVirtualizedSectionListT} from './Lists/VirtualizedSectionList'; @@ -38,6 +39,7 @@ export type { SectionData, } from './Lists/VirtualizedSectionList'; export type {FillRateInfo} from './Lists/FillRateHelper'; +export type VirtualizedListInstance = VirtualizedListInstanceT; export default { keyExtractor,