Skip to content

Commit 5437d14

Browse files
authored
Gentype: handle null/nullable/undefined from Stdlib (#7132)
* Gentype: handle null/nullable/undefined from Stdlib * CHANGELOG
1 parent 0fda872 commit 5437d14

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Allow single newline in JSX. https://github.com/rescript-lang/rescript/pull/7269
2222
- Editor: Always complete from Core first. Use actual native regex syntax in code snippets for regexps. https://github.com/rescript-lang/rescript/pull/7295
2323
- Add `type t` to Stdlib modules. https://github.com/rescript-lang/rescript/pull/7302
24+
- Gentype: handle null/nullable/undefined from Stdlib. https://github.com/rescript-lang/rescript/pull/7132
2425

2526
#### :bug: Bug fix
2627

compiler/gentype/TranslateTypeExprFromTypes.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,26 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
222222
{dependencies = []; type_ = EmitType.type_react_element}
223223
| (["FB"; "option"] | ["option"]), [param_translation] ->
224224
{param_translation with type_ = Option param_translation.type_}
225-
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
225+
| ( ( ["Js"; "Undefined"; "t"]
226+
| ["Undefined"; "t"]
227+
| ["Js"; "undefined"]
228+
| ["Stdlib"; "undefined"] ),
226229
[param_translation] ) ->
227230
{param_translation with type_ = Option param_translation.type_}
228231
| ( ( ["Js"; "Null"; "t"]
229232
| ["Null"; "t"]
230233
| ["Js"; "null"]
231-
| ["Stdlib"; "Null"; "t"] ),
234+
| ["Stdlib"; "Null"; "t"]
235+
| ["Stdlib"; "null"] ),
232236
[param_translation] ) ->
233237
{param_translation with type_ = Null param_translation.type_}
234238
| ( ( ["Js"; "Nullable"; "t"]
235239
| ["Nullable"; "t"]
236240
| ["Js"; "nullable"]
237241
| ["Js"; "Null_undefined"; "t"]
238242
| ["Js"; "null_undefined"]
239-
| ["Stdlib"; "Nullable"; "t"] ),
243+
| ["Stdlib"; "Nullable"; "t"]
244+
| ["Stdlib"; "nullable"] ),
240245
[param_translation] ) ->
241246
{param_translation with type_ = Nullable param_translation.type_}
242247
| ( ( ["Js"; "Promise"; "t"]

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

+20
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

+22-2
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)