-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple support to the Partial<T> annotation (#35961)
Summary: Pull Request resolved: #35961 Pull Request resolved: #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
- Loading branch information
1 parent
53932d0
commit 97e707d
Showing
10 changed files
with
984 additions
and
17 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
.../react-native-codegen/e2e/__test_fixtures__/modules/NativePartialAnnotationTurboModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.