Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial<Type> or $Partial<Type> are not supported in react-native-codegen #35864

Closed
vzaidman opened this issue Jan 17, 2023 · 0 comments
Closed
Labels
Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@vzaidman
Copy link
Contributor

Description

I'm trying to use the codegen to generate a TurboModule with the following type:

export type WindowBounds = {
  x: number;
  y: number;
  width: number;
  height: number;
};

export type WindowBoundsPartial = Partial<WindowBounds>;

But it fails with the error:

UnsupportedGenericParserError: Module NativeWindowModule: Unrecognized generic type 'Partial' in NativeModule spec.

This is a great feature that's supported both in TS (https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) and flow (https://flow.org/en/docs/types/utilities/#toc-partial).
Without this feature, I'll have to rewrite the type as

export type WindowBoundsPartial = {
  x?: number;
  y?: number;
  width?: number;
  height?: number;
};

I also tried defining Partial by myself:

type Partial2<T> = {
  [P in keyof T]?: T[P];
};

export type WindowBoundsPartial = Partial2<WindowBounds>;

But this fails too with the error:

UnsupportedTypeAnnotationParserError: Module NativeWindowModule: TypeScript type annotation 'TSMappedType' is unsupported in NativeModule specs.

Version

latest

Output of npx react-native info

n.a

Steps to reproduce

  • add
export type WindowBounds = {
  x: number;
  y: number;
  width: number;
  height: number;
};

export type WindowBoundsPartial = Partial<WindowBounds>;

to any Turbo Module spec file

  • try to run the codegen

Snack, code example, screenshot, or link to a repository

export type WindowBounds = {
  x: number;
  y: number;
  width: number;
  height: number;
};

export type WindowBoundsPartial = Partial<WindowBounds>;

@cortinico cortinico added the Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) label Jan 18, 2023
vzaidman added a commit to vzaidman/react-native that referenced this issue Jan 25, 2023
Summary:
Pull Request resolved: facebook#35961

Pull Request resolved: facebook#35960

This fixes facebook#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: 7f55e6cb2eec41f5e9d085b21b9ffd658b665140
vzaidman added a commit to vzaidman/react-native that referenced this issue Jan 25, 2023
Summary:
Pull Request resolved: facebook#35961

Pull Request resolved: facebook#35960

This fixes facebook#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: eba1ef64dd3a0c95d267a04f9e56cb8641ccbbf2
vzaidman added a commit to vzaidman/react-native that referenced this issue Jan 26, 2023
Summary:
Pull Request resolved: facebook#35961

Pull Request resolved: facebook#35960

This fixes facebook#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: e0b863c6863c312cc7b77438b326bfa5ed845d33
vzaidman added a commit to vzaidman/react-native that referenced this issue Jan 26, 2023
Summary:
Pull Request resolved: facebook#35961

Pull Request resolved: facebook#35960

This fixes facebook#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: 0caf8a600313d27efed83696359d0b3eca025303
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
Summary:
Pull Request resolved: facebook#35961

Pull Request resolved: facebook#35960

This fixes facebook#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants