From 7427a92004c874780c1abb5ca2c946846c83fbb1 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 23 Oct 2026 07:19:51 +0000 Subject: [PATCH] Translate char to number in genType Why: `char` is an alias of `int` since #8892, but genType's table of builtin types had no row for it and does not expand the abbreviation, so a `char` in a genType signature was emitted as the TypeScript type `char`, which does not exist. Representation modified (genType's TypeScript type of char): Example: @genType let char0 = (x: char) => x Before (text): export const char0: (x:char) => char = CoreJS.char0 as any; After (text): export const char0: (x:number) => number = CoreJS.char0 as any; Signed-off-by: Christoph Knittel Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xk6AeCYpCK4SZRtHYKHGoe --- changes/gentype-char-number.fix.md | 1 + compiler/gentype/translate_type_expr_from_types.ml | 2 +- .../gentype_tests/typescript-react-example/src/Core.gen.tsx | 2 ++ tests/gentype_tests/typescript-react-example/src/Core.res | 3 +++ tests/gentype_tests/typescript-react-example/src/Core.res.js | 5 +++++ 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changes/gentype-char-number.fix.md diff --git a/changes/gentype-char-number.fix.md b/changes/gentype-char-number.fix.md new file mode 100644 index 00000000000..89c236a7fe7 --- /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 1bf3110af1f..feae883c15f 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 113efbfacaa..fb657ed7c48 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 7f48f22459e..e0492b814e9 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 67291b187b7..db15342d01e 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,