diff --git a/CHANGELOG.md b/CHANGELOG.md index ea688636ef..5868d208c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ subset of the arguments, and return a curried type with the remaining ones https - Add support for toplevel `await` https://github.com/rescript-lang/rescript-compiler/pull/5940 - Support optional named arguments without a final unit in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5907 - Add experimental suppport for directives. An annotation such as `@@directive("use client;")` emits `use client;` verbatim before imports https://github.com/rescript-lang/rescript-compiler/pull/5998 +- `genType`: add `Core` standard library support for the following builtin types: `Null.t`, `Nullable.t`, `Undefined.t`, `Dict.t<_>`, `Promise.t<_>`, `Date.t`, `BigInt.t`, `RegExp.t`, `Map.t<_, _>`, `WeakMap.t<_, _>`, `Set<_>`, `WeakSet<_>` https://github.com/rescript-lang/rescript-compiler/pull/6019 #### :boom: Breaking Change @@ -39,6 +40,9 @@ subset of the arguments, and return a curried type with the remaining ones https Also, `(. int) => string => bool` is not equivalen to `(. int, string) => bool` anymore. These are only breaking changes for unformatted code. - Exponentiation operator `**` is now right-associative. `2. ** 3. ** 2.` now compile to `Math.pow(2, Math.pow(3, 2))` and not anymore `Math.pow(Math.pow(2, 3), 2)`. Parentheses can be used to change precedence. +- `genType`: streamline the treatment of optionals as undefined https://github.com/rescript-lang/rescript-compiler/pull/6022 + - Represent `option` as `undefined | t` instead of `null | undefined | t`. This is more permissive when importing functions taking optional values (allows to use option types), but stricter when e.g. exporting ReScript functions taking arguments of option type. Fallback: use `Js.undefined<_>` instead. + - Represent `{x:option}` as `{x:(undefined | string)}` instead of `{x?: string}`. This is more in line with TS's behaviour. Fallback: use `{x?:string}`. #### :bug: Bug Fix diff --git a/jscomp/gentype/Converter.ml b/jscomp/gentype/Converter.ml index a7090466d1..9a7d1c42a2 100644 --- a/jscomp/gentype/Converter.ml +++ b/jscomp/gentype/Converter.ml @@ -5,11 +5,9 @@ type t = | CircularC of string * t | FunctionC of functionC | IdentC - | NullableC of t | ObjectC of fieldsC | OptionC of t | PromiseC of t - | RecordC of fieldsC | TupleC of t list | VariantC of variantC @@ -68,8 +66,7 @@ let rec toString converter = |> String.concat ", ") ^ " -> " ^ toString retConverter ^ ")" | IdentC -> "id" - | NullableC c -> "nullable(" ^ toString c ^ ")" - | ObjectC fieldsC | RecordC fieldsC -> + | ObjectC fieldsC -> let dot = match converter with | ObjectC _ -> ". " @@ -120,6 +117,7 @@ let typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface | Array (t, mutable_) -> let tConverter, tNormalized = t |> visit ~visited in (ArrayC tConverter, Array (tNormalized, mutable_)) + | Dict _ -> (IdentC, normalized_) | Function ({argTypes; componentName; retType; typeVars; uncurried} as function_) -> @@ -189,10 +187,10 @@ let typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface else (IdentC, normalized_)) | Null t -> let tConverter, tNormalized = t |> visit ~visited in - (NullableC tConverter, Null tNormalized) + (OptionC tConverter, Null tNormalized) | Nullable t -> let tConverter, tNormalized = t |> visit ~visited in - (NullableC tConverter, Nullable tNormalized) + (OptionC tConverter, Nullable tNormalized) | Object (closedFlag, fields) -> let fieldsConverted = fields @@ -220,26 +218,6 @@ let typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface | Promise t -> let tConverter, tNormalized = t |> visit ~visited in (PromiseC tConverter, Promise tNormalized) - | Record fields -> - let fieldsConverted = - fields - |> List.map (fun ({type_} as field) -> (field, type_ |> visit ~visited)) - in - ( RecordC - (fieldsConverted - |> List.map (fun ({nameJS; nameRE; optional}, (converter, _)) -> - { - lblJS = nameJS; - lblRE = nameRE; - c = - (match optional = Mandatory with - | true -> converter - | false -> OptionC converter); - })), - Record - (fieldsConverted - |> List.map (fun (field, (_, tNormalized)) -> - {field with type_ = tNormalized})) ) | Tuple innerTypes -> let innerConversions, normalizedList = innerTypes |> List.map (visit ~visited) |> List.split @@ -379,7 +357,6 @@ let rec converterIsIdentity ~config ~toJS converter = argConverter |> converterIsIdentity ~config ~toJS:(not toJS) | GroupConverter _ -> false) | IdentC -> true - | NullableC c -> c |> converterIsIdentity ~config ~toJS | ObjectC fieldsC -> fieldsC |> List.for_all (fun {lblJS; lblRE; c} -> @@ -388,9 +365,8 @@ let rec converterIsIdentity ~config ~toJS converter = match c with | OptionC c1 -> c1 |> converterIsIdentity ~config ~toJS | _ -> c |> converterIsIdentity ~config ~toJS) - | OptionC c -> if toJS then c |> converterIsIdentity ~config ~toJS else false + | OptionC c -> c |> converterIsIdentity ~config ~toJS | PromiseC c -> c |> converterIsIdentity ~config ~toJS - | RecordC _ -> false | TupleC innerTypesC -> innerTypesC |> List.for_all (converterIsIdentity ~config ~toJS) | VariantC {withPayloads; useVariantTables} -> @@ -518,13 +494,6 @@ let rec apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables value = EmitText.funDef ~bodyArgs ~functionName:componentName ~funParams ~indent ~mkBody ~typeVars | IdentC -> value - | NullableC c -> - EmitText.parens - [ - value ^ " == null ? " ^ value ^ " : " - ^ (value - |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables); - ] | ObjectC fieldsC -> let simplifyFieldConverted fieldConverter = match fieldConverter with @@ -553,22 +522,12 @@ let rec apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables value = in "{" ^ fieldValues ^ "}" | OptionC c -> - if toJS then - EmitText.parens - [ - value ^ " == null ? " ^ value ^ " : " - ^ (value - |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables - ); - ] - else - EmitText.parens - [ - value ^ " == null ? undefined : " - ^ (value - |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables - ); - ] + EmitText.parens + [ + value ^ " == null ? " ^ value ^ " : " + ^ (value + |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables); + ] | PromiseC c -> let x = "$promise" |> EmitText.name ~nameGen in value ^ ".then(function _element(" @@ -576,39 +535,6 @@ let rec apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables value = ^ ") { return " ^ (x |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables) ^ "})" - | RecordC fieldsC -> - let simplifyFieldConverted fieldConverter = - match fieldConverter with - | OptionC converter1 when converter1 |> converterIsIdentity ~config ~toJS - -> - IdentC - | _ -> fieldConverter - in - if toJS then - let fieldValues = - fieldsC - |> List.mapi (fun index {lblJS; c = fieldConverter} -> - lblJS ^ ":" - ^ (value - |> EmitText.arrayAccess ~index - |> apply ~config - ~converter:(fieldConverter |> simplifyFieldConverted) - ~indent ~nameGen ~toJS ~variantTables)) - |> String.concat ", " - in - "{" ^ fieldValues ^ "}" - else - let fieldValues = - fieldsC - |> List.map (fun {lblJS; c = fieldConverter} -> - value - |> EmitText.fieldAccess ~label:lblJS - |> apply ~config - ~converter:(fieldConverter |> simplifyFieldConverted) - ~indent ~nameGen ~toJS ~variantTables) - |> String.concat ", " - in - "[" ^ fieldValues ^ "]" | TupleC innerTypesC -> "[" ^ (innerTypesC diff --git a/jscomp/gentype/EmitJs.ml b/jscomp/gentype/EmitJs.ml index 29ed058782..85e273a6c2 100644 --- a/jscomp/gentype/EmitJs.ml +++ b/jscomp/gentype/EmitJs.ml @@ -101,7 +101,7 @@ let typeNameIsInterface ~(exportTypeMap : CodeItem.exportTypeMap) ~(exportTypeMapFromOtherFiles : CodeItem.exportTypeMap) typeName = let typeIsInterface type_ = match type_ with - | Object _ | Record _ -> true + | Object _ -> true | _ -> false in match exportTypeMap |> StringMap.find typeName with @@ -620,11 +620,11 @@ let propagateAnnotationToSubTypes ~codeItems (typeMap : CodeItem.exportTypeMap) type1 |> visit | exception Not_found -> annotatedSet := !annotatedSet |> StringSet.add typeName) - | Array (t, _) -> t |> visit + | Array (t, _) | Dict t -> t |> visit | Function {argTypes; retType} -> argTypes |> List.iter (fun {aType} -> visit aType); retType |> visit - | GroupOfLabeledArgs fields | Object (_, fields) | Record fields -> + | GroupOfLabeledArgs fields | Object (_, fields) -> fields |> List.iter (fun {type_} -> type_ |> visit) | Option t | Null t | Nullable t | Promise t -> t |> visit | Tuple innerTypes -> innerTypes |> List.iter visit diff --git a/jscomp/gentype/EmitType.ml b/jscomp/gentype/EmitType.ml index 4c48468b35..c24f110b2e 100644 --- a/jscomp/gentype/EmitType.ml +++ b/jscomp/gentype/EmitType.ml @@ -95,6 +95,10 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface arrayName ^ "<" ^ (t |> renderType ~config ~indent ~typeNameIsInterface ~inFunType) ^ ">" + | Dict type_ -> + "{[id: string]: " + ^ (type_ |> renderType ~config ~indent ~typeNameIsInterface ~inFunType) + ^ "}" | Function {argTypes = [{aType = Object (closedFlag, fields)}]; retType; typeVars} when retType |> isTypeFunctionComponent ~fields -> @@ -116,7 +120,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface | Function {argTypes; retType; typeVars} -> renderFunType ~config ~indent ~inFunType ~typeNameIsInterface ~typeVars argTypes retType - | GroupOfLabeledArgs fields | Object (_, fields) | Record fields -> + | GroupOfLabeledArgs fields | Object (_, fields) -> let indent1 = fields |> Indent.heuristicFields ~indent in fields |> renderFields ~config ~indent:indent1 ~inFunType ~typeNameIsInterface @@ -136,7 +140,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface "(null | " ^ (type_ |> renderType ~config ~indent ~typeNameIsInterface ~inFunType) ^ ")" - | Nullable type_ | Option type_ -> + | Nullable type_ -> let useParens x = match type_ with | Function _ | Variant _ -> EmitText.parens [x] @@ -146,6 +150,16 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface ^ useParens (type_ |> renderType ~config ~indent ~typeNameIsInterface ~inFunType) ^ ")" + | Option type_ -> + let useParens x = + match type_ with + | Function _ | Variant _ -> EmitText.parens [x] + | _ -> x + in + "(undefined | " + ^ useParens + (type_ |> renderType ~config ~indent ~typeNameIsInterface ~inFunType) + ^ ")" | Promise type_ -> "Promise" ^ "<" ^ (type_ |> renderType ~config ~indent ~typeNameIsInterface ~inFunType) diff --git a/jscomp/gentype/GenTypeCommon.ml b/jscomp/gentype/GenTypeCommon.ml index ba8f357e33..b65dc1917a 100644 --- a/jscomp/gentype/GenTypeCommon.ml +++ b/jscomp/gentype/GenTypeCommon.ml @@ -59,6 +59,7 @@ type closedFlag = Open | Closed type type_ = | Array of type_ * mutable_ + | Dict of type_ | Function of function_ | GroupOfLabeledArgs of fields | Ident of ident @@ -67,7 +68,6 @@ type type_ = | Object of closedFlag * fields | Option of type_ | Promise of type_ - | Record of fields | Tuple of type_ list | TypeVar of string | Variant of variant @@ -108,6 +108,7 @@ and payload = {case: case; inlineRecord: bool; numArgs: int; t: type_} let typeIsObject type_ = match type_ with | Array _ -> true + | Dict _ -> true | Function _ -> false | GroupOfLabeledArgs _ -> false | Ident _ -> false @@ -116,7 +117,6 @@ let typeIsObject type_ = | Object _ -> true | Option _ -> false | Promise _ -> true - | Record _ -> true | Tuple _ -> true | TypeVar _ -> false | Variant _ -> false @@ -210,11 +210,17 @@ let sanitizeTypeName name = | '\'' -> '_' | c -> c) let unknown = ident "unknown" +let bigintT = ident "BigInt" let booleanT = ident "boolean" let dateT = ident "Date" +let mapT (x,y) = ident ~typeArgs:[x;y] "Map" let numberT = ident "number" +let regexpT = ident "RegExp" +let setT (x) = ident ~typeArgs:[x] "Set" let stringT = ident "string" let unitT = ident "void" +let weakmapT (x,y) = ident ~typeArgs:[x;y] "WeakMap" +let weaksetT (x) = ident ~typeArgs:[x] "WeakSet" let int64T = Tuple [numberT; numberT] module NodeFilename = struct diff --git a/jscomp/gentype/TranslateSignatureFromTypes.ml b/jscomp/gentype/TranslateSignatureFromTypes.ml index 9dff024d03..79a32969dc 100644 --- a/jscomp/gentype/TranslateSignatureFromTypes.ml +++ b/jscomp/gentype/TranslateSignatureFromTypes.ml @@ -12,8 +12,9 @@ let translateTypeDeclarationFromTypes ~config ~outputFileRelative ~resolver Log_.item "Translate Types.type_declaration %s\n" typeName; let declarationKind = match type_kind with - | Type_record (labelDeclarations, _) -> - TranslateTypeDeclarations.RecordDeclarationFromTypes labelDeclarations + | Type_record (labelDeclarations, recordRepresentation) -> + TranslateTypeDeclarations.RecordDeclarationFromTypes + (labelDeclarations, recordRepresentation) | Type_variant constructorDeclarations when not (TranslateTypeDeclarations.hasSomeGADTLeaf constructorDeclarations) diff --git a/jscomp/gentype/TranslateTypeDeclarations.ml b/jscomp/gentype/TranslateTypeDeclarations.ml index 62213f8205..a8229d876d 100644 --- a/jscomp/gentype/TranslateTypeDeclarations.ml +++ b/jscomp/gentype/TranslateTypeDeclarations.ml @@ -1,7 +1,8 @@ open GenTypeCommon type declarationKind = - | RecordDeclarationFromTypes of Types.label_declaration list + | RecordDeclarationFromTypes of + Types.label_declaration list * Types.record_representation | GeneralDeclaration of Typedtree.core_type option | GeneralDeclarationFromTypes of Types.type_expr option (** As the above, but from Types not Typedtree *) @@ -78,7 +79,12 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver in {CodeItem.importTypes; exportFromTypeDeclaration} in - let translateLabelDeclarations labelDeclarations = + let translateLabelDeclarations ~recordRepresentation labelDeclarations = + let isOptional l = + match recordRepresentation with + | Types.Record_optional_labels lbls -> List.mem l lbls + | _ -> false + in let fieldTranslations = labelDeclarations |> List.map (fun {Types.ld_id; ld_mutable; ld_type; ld_attributes} -> @@ -111,7 +117,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver -> let optional, type1 = match type_ with - | Option type1 -> (Optional, type1) + | Option type1 when isOptional nameRE -> (Optional, type1) | _ -> (Mandatory, type_) in {mutable_; nameJS; nameRE; optional; type_ = type1}) @@ -196,9 +202,10 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver in {translation with type_} |> handleGeneralDeclaration |> returnTypeDeclaration - | RecordDeclarationFromTypes labelDeclarations, None -> + | RecordDeclarationFromTypes (labelDeclarations, recordRepresentation), None + -> let {TranslateTypeExprFromTypes.dependencies; type_} = - labelDeclarations |> translateLabelDeclarations + labelDeclarations |> translateLabelDeclarations ~recordRepresentation in let importTypes = dependencies @@ -227,7 +234,11 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver |> TranslateTypeExprFromTypes.translateTypeExprsFromTypes ~config ~typeEnv | Cstr_record labelDeclarations -> - [labelDeclarations |> translateLabelDeclarations] + [ + labelDeclarations + |> translateLabelDeclarations + ~recordRepresentation:Types.Record_regular; + ] in let inlineRecord = match constructorArgs with @@ -342,8 +353,8 @@ let translateTypeDeclaration ~config ~outputFileRelative ~recursive ~resolver in let declarationKind = match typ_type.type_kind with - | Type_record (labelDeclarations, _) -> - RecordDeclarationFromTypes labelDeclarations + | Type_record (labelDeclarations, recordRepresentation) -> + RecordDeclarationFromTypes (labelDeclarations, recordRepresentation) | Type_variant constructorDeclarations -> VariantDeclarationFromTypes constructorDeclarations | Type_abstract -> GeneralDeclaration typ_manifest diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml index 573c5ed996..7d0b966474 100644 --- a/jscomp/gentype/TranslateTypeExprFromTypes.ml +++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml @@ -80,7 +80,34 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = | ["Js"; ("String" | "String2"); "t"] ), [] ) -> {dependencies = []; type_ = stringT} - | ["Js"; "Date"; "t"], [] -> {dependencies = []; type_ = dateT} + | (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] -> + {dependencies = []; type_ = bigintT} + | (["Js"; "Date"; "t"] | ["Date"; "t"]), [] -> + {dependencies = []; type_ = dateT} + | ["Map"; "t"], [paramTranslation1; paramTranslation2] -> + { + dependencies = + paramTranslation1.dependencies @ paramTranslation2.dependencies; + type_ = mapT (paramTranslation1.type_, paramTranslation2.type_); + } + | ["WeakMap"; "t"], [paramTranslation1; paramTranslation2] -> + { + dependencies = + paramTranslation1.dependencies @ paramTranslation2.dependencies; + type_ = weakmapT (paramTranslation1.type_, paramTranslation2.type_); + } + | ["Set"; "t"], [paramTranslation] -> + { + dependencies = paramTranslation.dependencies; + type_ = setT paramTranslation.type_; + } + | ["WeakSet"; "t"], [paramTranslation] -> + { + dependencies = paramTranslation.dependencies; + type_ = weaksetT paramTranslation.type_; + } + | (["Js"; "Re"; "t"] | ["RegExp"; "t"]), [] -> + {dependencies = []; type_ = regexpT} | (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unitT} | ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]), [paramTranslation] ) -> @@ -201,16 +228,24 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = {dependencies = []; type_ = EmitType.typeReactElement} | (["FB"; "option"] | ["option"]), [paramTranslation] -> {paramTranslation with type_ = Option paramTranslation.type_} - | (["Js"; "Null"; "t"] | ["Js"; "null"]), [paramTranslation] -> + | ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]), + [paramTranslation] ) -> + {paramTranslation with type_ = Option paramTranslation.type_} + | (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [paramTranslation] + -> {paramTranslation with type_ = Null paramTranslation.type_} | ( ( ["Js"; "Nullable"; "t"] + | ["Nullable"; "t"] | ["Js"; "nullable"] | ["Js"; "Null_undefined"; "t"] | ["Js"; "null_undefined"] ), [paramTranslation] ) -> {paramTranslation with type_ = Nullable paramTranslation.type_} - | (["Js"; "Promise"; "t"] | ["promise"]), [paramTranslation] -> + | ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]), + [paramTranslation] ) -> {paramTranslation with type_ = Promise paramTranslation.type_} + | (["Js"; "Dict"; "t"] | ["Dict"; "t"]), [paramTranslation] -> + {paramTranslation with type_ = Dict paramTranslation.type_} | ["function$"], [arg; _arity] -> { dependencies = arg.dependencies; diff --git a/jscomp/gentype/TypeVars.ml b/jscomp/gentype/TypeVars.ml index 05a9d3a1fe..780ea36dd1 100644 --- a/jscomp/gentype/TypeVars.ml +++ b/jscomp/gentype/TypeVars.ml @@ -30,6 +30,7 @@ let extractFromCoreType typeParams = let rec substitute ~f type0 = match type0 with | Array (t, arrayKind) -> Array (t |> substitute ~f, arrayKind) + | Dict type_ -> Dict (type_ |> substitute ~f) | Function function_ -> Function { @@ -57,11 +58,6 @@ let rec substitute ~f type0 = {field with type_ = field.type_ |> substitute ~f}) ) | Option type_ -> Option (type_ |> substitute ~f) | Promise type_ -> Promise (type_ |> substitute ~f) - | Record fields -> - Record - (fields - |> List.map (fun field -> - {field with type_ = field.type_ |> substitute ~f})) | Tuple innerTypes -> Tuple (innerTypes |> List.map (substitute ~f)) | TypeVar s -> ( match f s with @@ -84,7 +80,7 @@ let rec free_ type0 : StringSet.t = StringSet.diff ((argTypes |> freeOfList_) +++ (retType |> free_)) (typeVars |> StringSet.of_list) - | GroupOfLabeledArgs fields | Object (_, fields) | Record fields -> + | GroupOfLabeledArgs fields | Object (_, fields) -> fields |> List.fold_left (fun s {type_} -> StringSet.union s (type_ |> free_)) @@ -94,7 +90,7 @@ let rec free_ type0 : StringSet.t = |> List.fold_left (fun s typeArg -> StringSet.union s (typeArg |> free_)) StringSet.empty - | Null type_ | Nullable type_ -> type_ |> free_ + | Dict type_ | Null type_ | Nullable type_ -> type_ |> free_ | Option type_ | Promise type_ -> type_ |> free_ | Tuple innerTypes -> innerTypes diff --git a/jscomp/gentype_tests/typescript-react-example/src/BigInt.bs.js b/jscomp/gentype_tests/typescript-react-example/src/BigInt.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/BigInt.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/BigInt.res b/jscomp/gentype_tests/typescript-react-example/src/BigInt.res new file mode 100644 index 0000000000..2a3956d058 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/BigInt.res @@ -0,0 +1 @@ +type t = Js.Types.bigint_val \ No newline at end of file diff --git a/jscomp/gentype_tests/typescript-react-example/src/Core.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Core.bs.js new file mode 100644 index 0000000000..0864298fc2 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Core.bs.js @@ -0,0 +1,133 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as CoreGen from "./Core.gen"; + +function null0(x) { + return x; +} + +function null1(x) { + return x; +} + +function nullable0(x) { + return x; +} + +function nullable1(x) { + return x; +} + +function undefined0(x) { + return x; +} + +function undefined1(x) { + return x; +} + +function dict0(x) { + return x; +} + +function dict1(x) { + return x; +} + +function promise0(x) { + return x; +} + +function promise1(x) { + return x; +} + +function date0(x) { + return x; +} + +function date1(x) { + return x; +} + +function bigint0(x) { + return x; +} + +function bigint1(x) { + return x; +} + +function regexp0(x) { + return x; +} + +function regexp1(x) { + return x; +} + +function map1(x) { + return x; +} + +function weakmap1(x) { + return x; +} + +function set1(x) { + return x; +} + +function weakset1(x) { + return x; +} + +function option0(x) { + return x; +} + +function option1(x) { + return x; +} + +function someFunWithNullThenOptionalArgs(prim0, prim1) { + return CoreGen.someFunWithNullThenOptionalArgs(prim0, prim1); +} + +function someFunWithNullUndefinedArg(prim0, prim1) { + return CoreGen.someFunWithNullUndefinedArg(prim0, prim1); +} + +var $$Map; + +var $$Set; + +export { + null0 , + null1 , + nullable0 , + nullable1 , + undefined0 , + undefined1 , + dict0 , + dict1 , + promise0 , + promise1 , + date0 , + date1 , + bigint0 , + bigint1 , + regexp0 , + regexp1 , + $$Map , + $$Set , + map1 , + weakmap1 , + set1 , + weakset1 , + option0 , + option1 , + someFunWithNullThenOptionalArgs , + someFunWithNullUndefinedArg , +} +/* ./Core.gen Not a pure module */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx new file mode 100644 index 0000000000..8a5c6608f9 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx @@ -0,0 +1,86 @@ +/* TypeScript file generated from Core.res by genType. */ +/* eslint-disable import/first */ + + +import {someFunWithNullThenOptionalArgs as someFunWithNullThenOptionalArgsNotChecked} from './CoreTS'; + +import {someFunWithNullUndefinedArg as someFunWithNullUndefinedArgNotChecked} from './CoreTS'; + +const $$toJS552311971: { [key: string]: any } = {"0": "A"}; + +const $$toRE552311971: { [key: string]: any } = {"A": 0}; + +// In case of type error, check the type of 'someFunWithNullThenOptionalArgs' in 'Core.res' and './CoreTS'. +export const someFunWithNullThenOptionalArgsTypeChecked: (_1:(null | string), _2:(undefined | string)) => string = someFunWithNullThenOptionalArgsNotChecked; + +// Export 'someFunWithNullThenOptionalArgs' early to allow circular import from the '.bs.js' file. +export const someFunWithNullThenOptionalArgs: unknown = someFunWithNullThenOptionalArgsTypeChecked as (_1:(null | string), _2:(undefined | string)) => string; + +// In case of type error, check the type of 'someFunWithNullUndefinedArg' in 'Core.res' and './CoreTS'. +export const someFunWithNullUndefinedArgTypeChecked: (_1:(null | undefined | string), _2:number) => string = someFunWithNullUndefinedArgNotChecked; + +// Export 'someFunWithNullUndefinedArg' early to allow circular import from the '.bs.js' file. +export const someFunWithNullUndefinedArg: unknown = someFunWithNullUndefinedArgTypeChecked as (_1:(null | undefined | string), _2:number) => string; + +// tslint:disable-next-line:no-var-requires +const CoreBS = require('./Core.bs'); + +// tslint:disable-next-line:interface-over-type-literal +export type variant = "A" | { tag: "B"; value: string }; + +// tslint:disable-next-line:interface-over-type-literal +export type t1 = { readonly x?: string }; + +// tslint:disable-next-line:interface-over-type-literal +export type t2 = { readonly x: (undefined | string) }; + +export const null0: (x:(null | number)) => (null | number) = CoreBS.null0; + +export const null1: (x:(null | number)) => (null | number) = CoreBS.null1; + +export const nullable0: (x:(null | undefined | number)) => (null | undefined | number) = CoreBS.nullable0; + +export const nullable1: (x:(null | undefined | number)) => (null | undefined | number) = CoreBS.nullable1; + +export const undefined0: (x:(undefined | number)) => (undefined | number) = CoreBS.undefined0; + +export const undefined1: (x:(undefined | number)) => (undefined | number) = CoreBS.undefined1; + +export const dict0: (x:{[id: string]: string}) => {[id: string]: string} = CoreBS.dict0; + +export const dict1: (x:{[id: string]: string}) => {[id: string]: string} = CoreBS.dict1; + +export const promise0: (x:Promise) => Promise = CoreBS.promise0; + +export const promise1: (x:Promise) => Promise = CoreBS.promise1; + +export const date0: (x:Date) => Date = CoreBS.date0; + +export const date1: (x:Date) => Date = CoreBS.date1; + +export const bigint0: (x:BigInt) => BigInt = CoreBS.bigint0; + +export const bigint1: (x:BigInt) => BigInt = CoreBS.bigint1; + +export const regexp0: (x:RegExp) => RegExp = CoreBS.regexp0; + +export const regexp1: (x:RegExp) => RegExp = CoreBS.regexp1; + +export const map1: (x:Map) => Map = CoreBS.map1; + +export const weakmap1: (x:WeakMap) => WeakMap = CoreBS.weakmap1; + +export const set1: (x:Set) => Set = CoreBS.set1; + +export const weakset1: (x:WeakSet) => WeakSet = CoreBS.weakset1; + +export const option0: (x:(undefined | string)) => (undefined | string) = CoreBS.option0; + +export const option1: (x:(undefined | variant)) => (undefined | variant) = function (Arg1: any) { + const result = CoreBS.option1((Arg1 == null ? Arg1 : typeof(Arg1) === 'object' + ? {TAG: 0, _0:Arg1.value} as any + : $$toRE552311971[Arg1])); + return (result == null ? result : typeof(result) === 'object' + ? {tag:"B", value:result._0} + : $$toJS552311971[result]) +}; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Core.res b/jscomp/gentype_tests/typescript-react-example/src/Core.res new file mode 100644 index 0000000000..75fc44fe3b --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Core.res @@ -0,0 +1,88 @@ +@genType +let null0 = (x: Js.null) => x + +@genType +let null1 = (x: Null.t) => x + +@genType +let nullable0 = (x: Js.nullable) => x + +@genType +let nullable1 = (x: Nullable.t) => x + +@genType +let undefined0 = (x: Js.undefined) => x + +@genType +let undefined1 = (x: Undefined.t) => x + +@genType +let dict0 = (x: Js.Dict.t) => x + +@genType +let dict1 = (x: Dict.t) => x + +@genType +let promise0 = (x: promise) => x + +@genType +let promise1 = (x: Promise.t) => x + +@genType +let date0 = (x: Js.Date.t) => x + +@genType +let date1 = (x: Date.t) => x + +@genType +let bigint0 = (x: Js.Types.bigint_val) => x + +@genType +let bigint1 = (x: BigInt.t) => x + +@genType +let regexp0 = (x: Js.Re.t) => x + +@genType +let regexp1 = (x: RegExp.t) => x + +module Map = Map_ +module Set = Set_ + +@genType +let map1 = (x: Map.t) => x + +@genType +let weakmap1 = (x: WeakMap.t, int>) => x + +@genType +let set1 = (x: Set.t) => x + +@genType +let weakset1 = (x: WeakSet.t>) => x + +type variant = A | B(string) + +@genType +let option0 = (x: option) => x + +@genType +let option1 = (x: option) => x + +@genType +type t1 = {x?: string} + +@genType +type t2 = {x: Js.undefined} + +@genType.import("./CoreTS") +external someFunWithNullThenOptionalArgs: ( + Null.t /* Cannot be Nullable.t or option */, + option /* Cannot be Null.t or Nullable.t */, +) => string = "someFunWithNullThenOptionalArgs" + +@genType.import("./CoreTS") +external someFunWithNullUndefinedArg: ( + Nullable.t /* Can also be Null.t or option as they are subtypes */, + int, +) => string = "someFunWithNullUndefinedArg" diff --git a/jscomp/gentype_tests/typescript-react-example/src/CoreTS.ts b/jscomp/gentype_tests/typescript-react-example/src/CoreTS.ts new file mode 100644 index 0000000000..ef25fa71eb --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/CoreTS.ts @@ -0,0 +1,9 @@ +export declare function someFunWithNullThenOptionalArgs( + nullable: null | string, + app?: string +): string; + +export declare function someFunWithNullUndefinedArg( + nullUndefined: null | undefined | string, + other: number +): string; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Date.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Date.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Date.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Date.res b/jscomp/gentype_tests/typescript-react-example/src/Date.res new file mode 100644 index 0000000000..87cfe1b554 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Date.res @@ -0,0 +1 @@ +type t = Js.Date.t \ No newline at end of file diff --git a/jscomp/gentype_tests/typescript-react-example/src/Dict.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Dict.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Dict.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Dict.res b/jscomp/gentype_tests/typescript-react-example/src/Dict.res new file mode 100644 index 0000000000..444e46d661 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Dict.res @@ -0,0 +1 @@ +type t<'a> = Js.Dict.t<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx index e5a3949af4..66fda441c6 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx @@ -107,7 +107,7 @@ import type {polyType as $$polyType} from './MyMath'; import type {stringFunction as $$stringFunction} from './MyMath'; // tslint:disable-next-line:interface-over-type-literal -export type point = { readonly x: number; readonly y?: number }; +export type point = { readonly x: number; readonly y: (undefined | number) }; // tslint:disable-next-line:interface-over-type-literal export type numberOrString = $$numberOrString; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Map_.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Map_.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Map_.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Map_.res b/jscomp/gentype_tests/typescript-react-example/src/Map_.res new file mode 100644 index 0000000000..9f77470451 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Map_.res @@ -0,0 +1 @@ +type t<'k, 'v> diff --git a/jscomp/gentype_tests/typescript-react-example/src/Null.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Null.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Null.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Null.res b/jscomp/gentype_tests/typescript-react-example/src/Null.res new file mode 100644 index 0000000000..fff00a9895 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Null.res @@ -0,0 +1 @@ +type t<'a> = Js.null<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/Nullable.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Nullable.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Nullable.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Nullable.res b/jscomp/gentype_tests/typescript-react-example/src/Nullable.res new file mode 100644 index 0000000000..56a19212ce --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Nullable.res @@ -0,0 +1 @@ +type t<'a> = Js.nullable<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/Object.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Object.gen.tsx index 061e2ae084..31cd17915e 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Object.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Object.gen.tsx @@ -6,4 +6,4 @@ export type someType = { readonly crop?: string; readonly "fp-z"?: string }; // tslint:disable-next-line:interface-over-type-literal -export type someType2 = { readonly crop?: string; readonly "fp-z"?: string }; +export type someType2 = { readonly crop: (undefined | string); readonly "fp-z": (undefined | string) }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Promise.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Promise.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Promise.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Promise.res b/jscomp/gentype_tests/typescript-react-example/src/Promise.res new file mode 100644 index 0000000000..4e149cfece --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Promise.res @@ -0,0 +1 @@ +type t<'a> = promise<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx index 31ef5bb28a..65e582ba1a 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx @@ -16,21 +16,21 @@ import type {list} from '../src/shims/RescriptPervasives.shim'; export type coord = { readonly x: number; readonly y: number; - readonly z?: number + readonly z: (undefined | number) }; // tslint:disable-next-line:interface-over-type-literal export type person = { readonly name: string; readonly age: number; - readonly address?: string + readonly address: (undefined | string) }; // tslint:disable-next-line:interface-over-type-literal export type business = { readonly name: string; - readonly owner?: person; - readonly address?: string + readonly owner: (undefined | person); + readonly address: (undefined | string) }; // tslint:disable-next-line:interface-over-type-literal diff --git a/jscomp/gentype_tests/typescript-react-example/src/RegExp.bs.js b/jscomp/gentype_tests/typescript-react-example/src/RegExp.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/RegExp.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/RegExp.res b/jscomp/gentype_tests/typescript-react-example/src/RegExp.res new file mode 100644 index 0000000000..afd4e13e6f --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/RegExp.res @@ -0,0 +1 @@ +type t = Js.Re.t diff --git a/jscomp/gentype_tests/typescript-react-example/src/Set_.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Set_.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Set_.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Set_.res b/jscomp/gentype_tests/typescript-react-example/src/Set_.res new file mode 100644 index 0000000000..cfacdaa67e --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Set_.res @@ -0,0 +1 @@ +type t<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/TestImmutableArray.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/TestImmutableArray.gen.tsx index acb9f91d84..6ea14f6e0f 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/TestImmutableArray.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/TestImmutableArray.gen.tsx @@ -6,4 +6,4 @@ import * as TestImmutableArrayBS__Es6Import from './TestImmutableArray.bs'; const TestImmutableArrayBS: any = TestImmutableArrayBS__Es6Import; -export const testImmutableArrayGet: (arr:ReadonlyArray) => (null | undefined | T1) = TestImmutableArrayBS.testImmutableArrayGet; +export const testImmutableArrayGet: (arr:ReadonlyArray) => (undefined | T1) = TestImmutableArrayBS.testImmutableArrayGet; diff --git a/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx index 03444652a6..fb57d54ad6 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx @@ -21,7 +21,7 @@ export type toPayload = { readonly result: string }; export const convert: (_1:Promise) => Promise = TestPromiseBS.convert; -export const barx: (_1:{ readonly x?: Promise<(null | undefined | string)> }, _2:void) => boolean = function (Arg1: any, Arg2: any) { - const result = Curry._2(TestPromiseBS.barx, (Arg1.x == null ? undefined : Arg1.x.then(function _element($promise: any) { return ($promise == null ? undefined : $promise)})), Arg2); +export const barx: (_1:{ readonly x?: Promise<(undefined | string)> }, _2:void) => boolean = function (Arg1: any, Arg2: any) { + const result = Curry._2(TestPromiseBS.barx, Arg1.x, Arg2); return result }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/TransitiveType1.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/TransitiveType1.gen.tsx index c8ae43db6c..7d343e4543 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/TransitiveType1.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/TransitiveType1.gen.tsx @@ -10,12 +10,6 @@ import type {t2Alias as TransitiveType2_t2Alias} from './TransitiveType2.gen'; import type {t2 as TransitiveType2_t2} from './TransitiveType2.gen'; -export const convert: (x:TransitiveType2_t2) => TransitiveType2_t2 = function (Arg1: any) { - const result = TransitiveType1BS.convert((Arg1 == null ? undefined : Arg1)); - return result -}; +export const convert: (x:TransitiveType2_t2) => TransitiveType2_t2 = TransitiveType1BS.convert; -export const convertAlias: (x:TransitiveType2_t2Alias) => TransitiveType2_t2Alias = function (Arg1: any) { - const result = TransitiveType1BS.convertAlias((Arg1 == null ? undefined : Arg1)); - return result -}; +export const convertAlias: (x:TransitiveType2_t2Alias) => TransitiveType2_t2Alias = TransitiveType1BS.convertAlias; diff --git a/jscomp/gentype_tests/typescript-react-example/src/TransitiveType2.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/TransitiveType2.gen.tsx index 4d14e4870f..0ccf1b920c 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/TransitiveType2.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/TransitiveType2.gen.tsx @@ -5,7 +5,7 @@ import type {t3 as TransitiveType3_t3} from './TransitiveType3.gen'; // tslint:disable-next-line:interface-over-type-literal -export type t2 = (null | undefined | TransitiveType3_t3); +export type t2 = (undefined | TransitiveType3_t3); // tslint:disable-next-line:interface-over-type-literal export type t2Alias = t2; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Undefined.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Undefined.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Undefined.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Undefined.res b/jscomp/gentype_tests/typescript-react-example/src/Undefined.res new file mode 100644 index 0000000000..5c2e5dc3de --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/Undefined.res @@ -0,0 +1 @@ +type t<'a> = Js.undefined<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx index 4ed7a98575..7244a0abe3 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx @@ -112,7 +112,7 @@ export const id2: (x:x2) => x2 = function (Arg1: any) { return $$toJS1061900109[result] }; -export const polyWithOpt: (foo:string) => (null | undefined | ( +export const polyWithOpt: (foo:string) => (undefined | ( { NAME: "One"; VAL: string } | { NAME: "Two"; VAL: number })) = VariantsBS.polyWithOpt; diff --git a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res index 50233719d7..cafe5347a7 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res +++ b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res @@ -1,6 +1,6 @@ type payload = { x: int, - y: option, + y?: string, } type withPayload = [ diff --git a/jscomp/gentype_tests/typescript-react-example/src/WeakMap.bs.js b/jscomp/gentype_tests/typescript-react-example/src/WeakMap.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/WeakMap.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/WeakMap.res b/jscomp/gentype_tests/typescript-react-example/src/WeakMap.res new file mode 100644 index 0000000000..9f77470451 --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/WeakMap.res @@ -0,0 +1 @@ +type t<'k, 'v> diff --git a/jscomp/gentype_tests/typescript-react-example/src/WeakSet.bs.js b/jscomp/gentype_tests/typescript-react-example/src/WeakSet.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/WeakSet.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/WeakSet.res b/jscomp/gentype_tests/typescript-react-example/src/WeakSet.res new file mode 100644 index 0000000000..cfacdaa67e --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/WeakSet.res @@ -0,0 +1 @@ +type t<'a> diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx index d5fb83f805..67223c651e 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx @@ -11,7 +11,7 @@ import * as TuplesBS__Es6Import from './Tuples.bs'; const TuplesBS: any = TuplesBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal -export type coord = [number, number, (null | undefined | number)]; +export type coord = [number, number, (undefined | number)]; // tslint:disable-next-line:interface-over-type-literal export type coord2 = [number, number, (null | undefined | number)]; @@ -24,21 +24,15 @@ export type couple = [person, person]; export const testTuple: (param:[number, number]) => number = TuplesBS.testTuple; -export const origin: [number, number, (null | undefined | number)] = TuplesBS.origin; +export const origin: [number, number, (undefined | number)] = TuplesBS.origin; -export const computeArea: (param:[number, number, (null | undefined | number)]) => number = function (Arg1: any) { - const result = TuplesBS.computeArea([Arg1[0], Arg1[1], (Arg1[2] == null ? undefined : Arg1[2])]); - return result -}; +export const computeArea: (param:[number, number, (undefined | number)]) => number = TuplesBS.computeArea; -export const computeAreaWithIdent: (param:coord) => number = function (Arg1: any) { - const result = TuplesBS.computeAreaWithIdent([Arg1[0], Arg1[1], (Arg1[2] == null ? undefined : Arg1[2])]); - return result -}; +export const computeAreaWithIdent: (param:coord) => number = TuplesBS.computeAreaWithIdent; export const computeAreaNoConverters: (param:[number, number]) => number = TuplesBS.computeAreaNoConverters; -export const coord2d: (x:T1, y:T2) => [T1, T2, (null | undefined | T3)] = function (Arg1: any, Arg2: any) { +export const coord2d: (x:T1, y:T2) => [T1, T2, (undefined | T3)] = function (Arg1: any, Arg2: any) { const result = Curry._2(TuplesBS.coord2d, Arg1, Arg2); return result }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx index 1c7fff0692..3195af09e6 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx @@ -10,8 +10,6 @@ const Curry: any = Curry__Es6Import; import * as TypesBS__Es6Import from './Types.bs'; const TypesBS: any = TypesBS__Es6Import; -import type {Dict_t as Js_Dict_t} from '../../src/shims/Js.shim'; - import type {Json_t as Js_Json_t} from '../../src/shims/Js.shim'; import type {M_t__ as TypeNameSanitize_M_t__} from '../../src/TypeNameSanitize.gen'; @@ -57,7 +55,7 @@ export type twice = [a, a]; export type genTypeMispelled = number; // tslint:disable-next-line:interface-over-type-literal -export type dictString = Js_Dict_t; +export type dictString = {[id: string]: string}; // tslint:disable-next-line:interface-over-type-literal export type nullOrString = (null | string); @@ -128,8 +126,8 @@ export const selfRecursiveConverter: (param:selfRecursive) => selfRecursive = Ty export const mutuallyRecursiveConverter: (param:mutuallyRecursiveA) => mutuallyRecursiveB = TypesBS.mutuallyRecursiveConverter; -export const testFunctionOnOptionsAsArgument: (a:(null | undefined | a), foo:((_1:(null | undefined | a)) => T1)) => T1 = function (Arg1: any, Arg2: any) { - const result = Curry._2(TypesBS.testFunctionOnOptionsAsArgument, (Arg1 == null ? undefined : Arg1), Arg2); +export const testFunctionOnOptionsAsArgument: (a:(undefined | a), foo:((_1:(undefined | a)) => T1)) => T1 = function (Arg1: any, Arg2: any) { + const result = Curry._2(TypesBS.testFunctionOnOptionsAsArgument, Arg1, Arg2); return result }; @@ -155,4 +153,4 @@ export const currentTime: Date = TypesBS.currentTime; export const i64Const: i64B = TypesBS.i64Const; -export const optFunction: (null | undefined | (() => number)) = TypesBS.optFunction; +export const optFunction: (undefined | (() => number)) = TypesBS.optFunction; diff --git a/jscomp/gentype_tests/typescript-react-example/src/shims/Js.shim.ts b/jscomp/gentype_tests/typescript-react-example/src/shims/Js.shim.ts index f89f1b26c4..7c735117fd 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/shims/Js.shim.ts +++ b/jscomp/gentype_tests/typescript-react-example/src/shims/Js.shim.ts @@ -1,5 +1,3 @@ -export type Dict_t = {[id: string]: T}; - export type Json_t = unknown; export type t = unknown;