From cf095dea99168b521be8e3894716b72e29b6bbe0 Mon Sep 17 00:00:00 2001 From: Larko <59736843+Larkooo@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:01:36 -0500 Subject: [PATCH] fix: typescript plugin for non struct fields (#1608) * fix: typescript plugin for non struct fields * fix: primitive type arg in system * chore: fmt --- .../src/plugins/typescript/mod.rs | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/dojo-bindgen/src/plugins/typescript/mod.rs b/crates/dojo-bindgen/src/plugins/typescript/mod.rs index 305e91d8f9..91f50d6306 100644 --- a/crates/dojo-bindgen/src/plugins/typescript/mod.rs +++ b/crates/dojo-bindgen/src/plugins/typescript/mod.rs @@ -268,23 +268,25 @@ export function defineContractComponents(world: World) { .inputs .iter() .map(|arg| { - let token = arg.1.to_composite().unwrap(); - // r#type doesnt seem to be working rn. - // instead, we can take a look at our - // handled tokens db - let token = - handled_tokens.iter().find(|t| t.type_name() == token.type_name()).unwrap(); - - match token.r#type { - CompositeType::Struct => token - .inners - .iter() - .map(|field| format!("props.{}.{}", arg.0, field.name)) - .collect::>() - .join(",\n "), - _ => { - format!("props.{}", arg.0) + let token = &arg.1; + let type_name = &arg.0; + + match handled_tokens.iter().find(|t| t.type_name() == token.type_name()) { + Some(t) => { + // Need to flatten the struct members. + match t.r#type { + CompositeType::Struct => t + .inners + .iter() + .map(|field| format!("props.{}.{}", type_name, field.name)) + .collect::>() + .join(",\n "), + _ => { + format!("props.{}", type_name) + } + } } + None => format!("props.{}", type_name), } }) .collect::>()