Files
react-native/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativePartialAnnotationTurboModule.js
T
Vitali Zaidman 97e707d897 simple support to the Partial<T> annotation (#35961)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35961

Pull Request resolved: https://github.com/facebook/react-native/pull/35960

This fixes #35864

This feature allows using `$Partial<Obj>` in flow and `Partial<Obj>` in TypeScript based on the spec mentioned here: https://flow.org/en/docs/types/utilities/#toc-partial.

We currently only allow passing an Obj to Partial so
```
export type SomeObj = {
  a: string,
  b?: boolean,
};

export type PartialSomeObj = Partial<SomeObj>;
```
should work.
and also-
```
export type PartialSomeObj = Partial<{
  a: string,
  b?: boolean,
}>;
```
But not
```
export type PartialSomeObj = Partial<Partial<{
  a: string,
  b?: boolean,
}>>;
```
This can be improved in the future by a recursive unwrapping of the value inside the `Partial` annotation.

Changelog:
[General] [Added] -  Allow the use of "Partial<T>" in Turbo Module specs.

Reviewed By: christophpurrer, cipolleschi

Differential Revision: D42640880

fbshipit-source-id: 03a3fccc38ccfc7a5440fe11893beb68e77753f3
2023-01-26 12:30:38 -08:00

36 lines
926 B
JavaScript

/**
* 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.
*
* @flow strict-local
* @format
*/
'use strict';
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
export type SomeObj = {|
a: string,
b?: boolean,
|};
export type PartialSomeObj = $Partial<SomeObj>;
export interface Spec extends TurboModule {
+getSomeObj: () => SomeObj;
+getPartialSomeObj: () => $Partial<SomeObj>;
+getSomeObjFromPartialSomeObj: (value: $Partial<SomeObj>) => SomeObj;
+getPartialPartial: (
value1: $Partial<SomeObj>,
value2: PartialSomeObj,
) => SomeObj;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(
'NativePartialAnnotationTurboModule',
): Spec);