From abfe2bdd3db22c829abc6aa6b489f445ee349f1c Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 27 Oct 2024 08:47:15 +0100 Subject: [PATCH] Gentype: handle null/nullable/undefined from Pervasives --- .../gentype/TranslateTypeExprFromTypes.ml | 15 ++++++++---- .../package-lock.json | 2 +- .../src/nested/Types.gen.tsx | 20 ++++++++++++++++ .../src/nested/Types.res | 24 +++++++++++++++++-- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/compiler/gentype/TranslateTypeExprFromTypes.ml b/compiler/gentype/TranslateTypeExprFromTypes.ml index d559a8215a..aa4b355c37 100644 --- a/compiler/gentype/TranslateTypeExprFromTypes.ml +++ b/compiler/gentype/TranslateTypeExprFromTypes.ml @@ -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"]), diff --git a/tests/gentype_tests/typescript-react-example/package-lock.json b/tests/gentype_tests/typescript-react-example/package-lock.json index 3d1726bcb8..090c2be357 100644 --- a/tests/gentype_tests/typescript-react-example/package-lock.json +++ b/tests/gentype_tests/typescript-react-example/package-lock.json @@ -22,7 +22,7 @@ }, "../../..": { "name": "rescript", - "version": "12.0.0-alpha.4", + "version": "12.0.0-alpha.5", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", diff --git a/tests/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx b/tests/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx index d497835c0e..cda2b782d6 100644 --- a/tests/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx +++ b/tests/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx @@ -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 = (_1:a) => b; diff --git a/tests/gentype_tests/typescript-react-example/src/nested/Types.res b/tests/gentype_tests/typescript-react-example/src/nested/Types.res index 54fa80803c..7b5b79ca77 100644 --- a/tests/gentype_tests/typescript-react-example/src/nested/Types.res +++ b/tests/gentype_tests/typescript-react-example/src/nested/Types.res @@ -64,9 +64,29 @@ type genTypeMispelled = int @genType let jsonStringify = Js.Json.stringify -@genType type nullOrString = Js.Null.t +@genType type nullOrString = null -@genType type nullOrString2 = Js.null +@genType type nullOrString2 = Null.t + +@genType type nullOrString3 = Js.null + +@genType type nullOrString4 = Js.Null.t + +@genType type nullableOrString = nullable + +@genType type nullableOrString2 = Nullable.t + +@genType type nullableOrString3 = Js.nullable + +@genType type nullableOrString4 = Js.Nullable.t + +@genType type undefinedOrString = undefined + +@genType type undefinedOrString2 = Undefined.t + +@genType type undefinedOrString3 = Js.undefined + +@genType type undefinedOrString4 = Js.Undefined.t type record = { i: int,