Skip to content

Commit abfe2bd

Browse files
committed
Gentype: handle null/nullable/undefined from Pervasives
1 parent 3b93359 commit abfe2bd

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,24 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
213213
{dependencies = []; type_ = EmitType.type_react_element}
214214
| (["FB"; "option"] | ["option"]), [param_translation] ->
215215
{param_translation with type_ = Option param_translation.type_}
216-
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
216+
| ( ( ["Js"; "Undefined"; "t"]
217+
| ["Undefined"; "t"]
218+
| ["Js"; "undefined"]
219+
| ["Pervasives"; "undefined"] ),
217220
[param_translation] ) ->
218221
{param_translation with type_ = Option param_translation.type_}
219-
| (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [param_translation]
220-
->
222+
| ( ( ["Js"; "Null"; "t"]
223+
| ["Null"; "t"]
224+
| ["Js"; "null"]
225+
| ["Pervasives"; "null"] ),
226+
[param_translation] ) ->
221227
{param_translation with type_ = Null param_translation.type_}
222228
| ( ( ["Js"; "Nullable"; "t"]
223229
| ["Nullable"; "t"]
224230
| ["Js"; "nullable"]
225231
| ["Js"; "Null_undefined"; "t"]
226-
| ["Js"; "null_undefined"] ),
232+
| ["Js"; "null_undefined"]
233+
| ["Pervasives"; "nullable"] ),
227234
[param_translation] ) ->
228235
{param_translation with type_ = Nullable param_translation.type_}
229236
| ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]),

tests/gentype_tests/typescript-react-example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ export type nullOrString = (null | string);
4747

4848
export type nullOrString2 = (null | string);
4949

50+
export type nullOrString3 = (null | string);
51+
52+
export type nullOrString4 = (null | string);
53+
54+
export type nullableOrString = (null | undefined | string);
55+
56+
export type nullableOrString2 = (null | undefined | string);
57+
58+
export type nullableOrString3 = (null | undefined | string);
59+
60+
export type nullableOrString4 = (null | undefined | string);
61+
62+
export type undefinedOrString = (undefined | string);
63+
64+
export type undefinedOrString2 = (undefined | string);
65+
66+
export type undefinedOrString3 = (undefined | string);
67+
68+
export type undefinedOrString4 = (undefined | string);
69+
5070
export type record = { readonly i: number; readonly s: string };
5171

5272
export type decorator<a,b> = (_1:a) => b;

tests/gentype_tests/typescript-react-example/src/nested/Types.res

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,29 @@ type genTypeMispelled = int
6464

6565
@genType let jsonStringify = Js.Json.stringify
6666

67-
@genType type nullOrString = Js.Null.t<string>
67+
@genType type nullOrString = null<string>
6868

69-
@genType type nullOrString2 = Js.null<string>
69+
@genType type nullOrString2 = Null.t<string>
70+
71+
@genType type nullOrString3 = Js.null<string>
72+
73+
@genType type nullOrString4 = Js.Null.t<string>
74+
75+
@genType type nullableOrString = nullable<string>
76+
77+
@genType type nullableOrString2 = Nullable.t<string>
78+
79+
@genType type nullableOrString3 = Js.nullable<string>
80+
81+
@genType type nullableOrString4 = Js.Nullable.t<string>
82+
83+
@genType type undefinedOrString = undefined<string>
84+
85+
@genType type undefinedOrString2 = Undefined.t<string>
86+
87+
@genType type undefinedOrString3 = Js.undefined<string>
88+
89+
@genType type undefinedOrString4 = Js.Undefined.t<string>
7090

7191
type record = {
7292
i: int,

0 commit comments

Comments
 (0)