From f4b32f650c403e5cbd1684929006c1ffcd6898c7 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Wed, 28 May 2025 13:20:03 +0200 Subject: [PATCH] Make optional types better optional in typescript --- libjrpc/src/targets/typescript.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libjrpc/src/targets/typescript.rs b/libjrpc/src/targets/typescript.rs index 205ea48..0e49213 100644 --- a/libjrpc/src/targets/typescript.rs +++ b/libjrpc/src/targets/typescript.rs @@ -476,9 +476,12 @@ impl Compile for TypeScriptCompiler { for field in definition.fields.iter() { let typ = Self::type_to_typescript_ext(&field.typ); + let opt = if field.typ.is_optional() { "?" } else { "" }; + f.a1(format!( - "public {}: {};", + "public {}{}: {};", Self::fix_keyword_name(&field.name), + opt, typ )); }