From d6031bae10d817eb5229e6321b18197dc434300b Mon Sep 17 00:00:00 2001 From: Gonzalo Chumillas Date: Mon, 19 May 2025 14:35:22 +0100 Subject: [PATCH] jsgen: fix casting (fix #24512) (#24519) --- vlib/v/gen/js/js.v | 2 +- vlib/v/gen/js/tests/casting.v | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 vlib/v/gen/js/tests/casting.v diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index f4b8fcc60..6b3547845 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -872,8 +872,8 @@ fn (mut g JsGen) expr(node_ ast.Expr) { g.gen_array_init_expr(node) } ast.AsCast { - // skip: JS has no types, so no need to cast // TODO: Is jsdoc needed here for TS support? + g.expr(node.expr) } ast.Assoc { // TODO diff --git a/vlib/v/gen/js/tests/casting.v b/vlib/v/gen/js/tests/casting.v new file mode 100644 index 000000000..838bead5f --- /dev/null +++ b/vlib/v/gen/js/tests/casting.v @@ -0,0 +1,6 @@ +type Type = string | bool + +fn main() { + t := Type('') + assert t is string && t == '' +} -- 2.39.5