in compiler/crates/relay-typegen/src/typescript.rs [184:248]
fn write_object(&mut self, props: &[Prop]) -> FmtResult {
if props.is_empty() {
write!(&mut self.result, "{{}}")?;
return Ok(());
}
// Replication of babel printer oddity: objects only containing a spread
// are missing a newline.
if props.len() == 1 {
if let Prop::Spread(_) = props[0] {
write!(&mut self.result, "{{}}")?;
return Ok(());
}
}
writeln!(&mut self.result, "{{")?;
self.indentation += 1;
for prop in props {
match prop {
Prop::Spread(_) => continue,
Prop::KeyValuePair(key_value_pair) => {
self.write_indentation()?;
if let AST::OtherTypename = key_value_pair.value {
writeln!(
&mut self.result,
"// This will never be '%other', but we need some"
)?;
self.write_indentation()?;
writeln!(
&mut self.result,
"// value in case none of the concrete values match."
)?;
self.write_indentation()?;
}
if key_value_pair.read_only {
write!(&mut self.result, "readonly ")?;
}
if key_value_pair.key == *KEY_FRAGMENT_SPREADS
|| key_value_pair.key == *KEY_FRAGMENT_TYPE
|| key_value_pair.key == *KEY_DATA
{
write!(&mut self.result, "\" {}\"", key_value_pair.key)?;
} else {
write!(&mut self.result, "{}", key_value_pair.key)?;
}
if key_value_pair.optional {
write!(&mut self.result, "?")?;
}
write!(&mut self.result, ": ")?;
self.write(&key_value_pair.value)?;
writeln!(&mut self.result, ";")?;
}
Prop::GetterSetterPair(_) => {
panic!(
"Getters and setters with different types are not implemented in typescript. See https://github.com/microsoft/TypeScript/issues/43662"
);
}
}
}
self.indentation -= 1;
self.write_indentation()?;
write!(&mut self.result, "}}")?;
Ok(())
}