You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let offending_line_end = contents[line_start_idx..]
651
-
.find('\n')
652
-
.map(|i| line_start_idx + i)
653
-
.unwrap_or(contents.len());
654
-
let offending_snippet = contents[line_start_idx..offending_line_end].trim();
655
-
656
-
missing_optional_marker.insert(format!(
657
-
"{}:{}: {offending_snippet}",
658
-
path.display(),
659
-
line_number
660
-
));
661
-
662
716
search_start = abs_idx + 5;
663
717
}
664
718
}
@@ -670,12 +724,12 @@ mod tests {
670
724
"Generated TypeScript still includes unions with `undefined` in {undefined_offenders:?}"
671
725
);
672
726
673
-
// If this test fails, it means that a struct field that is `Option<T>` in Rust
674
-
// is being generated as `T | null` in TypeScript, without the optional marker
675
-
// (`?`). To fix this, add #[ts(optional_fields = nullable)] to the struct definition.
727
+
// If this assertion fails, it means a field was generated as
728
+
// "?: T | null" — i.e., both optional (undefined) and nullable (null).
729
+
// We only want either "?: T" or ": T | null".
676
730
assert!(
677
-
missing_optional_marker.is_empty(),
678
-
"Generated TypeScript has nullable fields without an optional marker: {missing_optional_marker:?}"
731
+
optional_nullable_offenders.is_empty(),
732
+
"Generated TypeScript has optional fields with nullable types (disallowed '?: T | null'), add #[ts(optional)] to fix:\n{optional_nullable_offenders:?}"
0 commit comments