diff --git a/changes/gentype-char-number.fix.md b/changes/gentype-char-number.fix.md new file mode 100644 index 0000000000..89c236a7fe --- /dev/null +++ b/changes/gentype-char-number.fix.md @@ -0,0 +1 @@ +- genType emits `char` as the TypeScript type `number` instead of `char`, which TypeScript does not know. diff --git a/compiler/gentype/translate_type_expr_from_types.ml b/compiler/gentype/translate_type_expr_from_types.ml index 1bf3110af1..feae883c15 100644 --- a/compiler/gentype/translate_type_expr_from_types.ml +++ b/compiler/gentype/translate_type_expr_from_types.ml @@ -67,7 +67,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env = in match (path |> path_to_list |> List.rev, params_translation) with | ["bool"], [] -> {dependencies = []; type_ = boolean_t} - | ["int"], [] -> {dependencies = []; type_ = number_t} + | (["int"] | ["char"]), [] -> {dependencies = []; type_ = number_t} | ["float"], [] -> {dependencies = []; type_ = number_t} | (["string"] | ["Stdlib"; "String"; "t"]), [] -> {dependencies = []; type_ = string_t} diff --git a/tests/gentype_tests/typescript-react-example/src/Core.gen.tsx b/tests/gentype_tests/typescript-react-example/src/Core.gen.tsx index 113efbfaca..fb657ed7c4 100644 --- a/tests/gentype_tests/typescript-react-example/src/Core.gen.tsx +++ b/tests/gentype_tests/typescript-react-example/src/Core.gen.tsx @@ -51,6 +51,8 @@ export const taggedTemplate1: (x:((strings:TemplateStringsArray, ...values:strin export const date1: (x:Date) => Date = CoreJS.date1 as any; +export const char0: (x:number) => number = CoreJS.char0 as any; + export const bigint0: (x:bigint) => bigint = CoreJS.bigint0 as any; export const stdlibBigInt: (x:bigint) => bigint = CoreJS.stdlibBigInt as any; diff --git a/tests/gentype_tests/typescript-react-example/src/Core.res b/tests/gentype_tests/typescript-react-example/src/Core.res index 7f48f22459..e0492b814e 100644 --- a/tests/gentype_tests/typescript-react-example/src/Core.res +++ b/tests/gentype_tests/typescript-react-example/src/Core.res @@ -34,6 +34,9 @@ let taggedTemplate1 = (x: TaggedTemplate.t) => x @genType let date1 = (x: Date.t) => x +@genType +let char0 = (x: char) => x + @genType let bigint0 = (x: bigint) => x diff --git a/tests/gentype_tests/typescript-react-example/src/Core.res.js b/tests/gentype_tests/typescript-react-example/src/Core.res.js index 67291b187b..db15342d01 100644 --- a/tests/gentype_tests/typescript-react-example/src/Core.res.js +++ b/tests/gentype_tests/typescript-react-example/src/Core.res.js @@ -50,6 +50,10 @@ function date1(x) { return x; } +function char0(x) { + return x; +} + function bigint0(x) { return x; } @@ -119,6 +123,7 @@ export { taggedTemplate0, taggedTemplate1, date1, + char0, bigint0, stdlibBigInt, regexp1,