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

Gentype: handle null/nullable/undefined from Pervasives #7132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,24 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
{dependencies = []; type_ = EmitType.type_react_element}
| (["FB"; "option"] | ["option"]), [param_translation] ->
{param_translation with type_ = Option param_translation.type_}
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
| ( ( ["Js"; "Undefined"; "t"]
| ["Undefined"; "t"]
| ["Js"; "undefined"]
| ["Pervasives"; "undefined"] ),
[param_translation] ) ->
{param_translation with type_ = Option param_translation.type_}
| (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [param_translation]
->
| ( ( ["Js"; "Null"; "t"]
| ["Null"; "t"]
| ["Js"; "null"]
| ["Pervasives"; "null"] ),
[param_translation] ) ->
{param_translation with type_ = Null param_translation.type_}
| ( ( ["Js"; "Nullable"; "t"]
| ["Nullable"; "t"]
| ["Js"; "nullable"]
| ["Js"; "Null_undefined"; "t"]
| ["Js"; "null_undefined"] ),
| ["Js"; "null_undefined"]
| ["Pervasives"; "nullable"] ),
[param_translation] ) ->
{param_translation with type_ = Nullable param_translation.type_}
| ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ export type nullOrString = (null | string);

export type nullOrString2 = (null | string);

export type nullOrString3 = (null | string);

export type nullOrString4 = (null | string);

export type nullableOrString = (null | undefined | string);

export type nullableOrString2 = (null | undefined | string);

export type nullableOrString3 = (null | undefined | string);

export type nullableOrString4 = (null | undefined | string);

export type undefinedOrString = (undefined | string);

export type undefinedOrString2 = (undefined | string);

export type undefinedOrString3 = (undefined | string);

export type undefinedOrString4 = (undefined | string);

export type record = { readonly i: number; readonly s: string };

export type decorator<a,b> = (_1:a) => b;
Expand Down
24 changes: 22 additions & 2 deletions tests/gentype_tests/typescript-react-example/src/nested/Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,29 @@ type genTypeMispelled = int

@genType let jsonStringify = Js.Json.stringify

@genType type nullOrString = Js.Null.t<string>
@genType type nullOrString = null<string>

@genType type nullOrString2 = Js.null<string>
@genType type nullOrString2 = Null.t<string>

@genType type nullOrString3 = Js.null<string>

@genType type nullOrString4 = Js.Null.t<string>

@genType type nullableOrString = nullable<string>

@genType type nullableOrString2 = Nullable.t<string>

@genType type nullableOrString3 = Js.nullable<string>

@genType type nullableOrString4 = Js.Nullable.t<string>

@genType type undefinedOrString = undefined<string>

@genType type undefinedOrString2 = Undefined.t<string>

@genType type undefinedOrString3 = Js.undefined<string>

@genType type undefinedOrString4 = Js.Undefined.t<string>

type record = {
i: int,
Expand Down