Skip to content

Commit

Permalink
Gentype: handle null/nullable/undefined from Pervasives
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt committed Oct 27, 2024
1 parent 3b93359 commit abfe2bd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
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

0 comments on commit abfe2bd

Please sign in to comment.