Skip to content

Commit

Permalink
Gentype: handle null/nullable/undefined from Stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt committed Feb 18, 2025
1 parent 0fda872 commit d270512
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
11 changes: 8 additions & 3 deletions compiler/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,26 @@ 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"]
| ["Stdlib"; "undefined"] ),
[param_translation] ) ->
{param_translation with type_ = Option param_translation.type_}
| ( ( ["Js"; "Null"; "t"]
| ["Null"; "t"]
| ["Js"; "null"]
| ["Stdlib"; "Null"; "t"] ),
| ["Stdlib"; "Null"; "t"]
| ["Stdlib"; "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"]
| ["Stdlib"; "Nullable"; "t"] ),
| ["Stdlib"; "Nullable"; "t"]
| ["Stdlib"; "nullable"] ),
[param_translation] ) ->
{param_translation with type_ = Nullable param_translation.type_}
| ( ( ["Js"; "Promise"; "t"]
Expand Down
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 d270512

Please sign in to comment.