Skip to main content

tsync/to_typescript/
type_item.rs

1use crate::BuildState;
2use syn::ext::IdentExt;
3
4impl super::ToTypescript for syn::ItemType {
5    fn convert_to_ts(self, state: &mut BuildState, config: &crate::BuildSettings) {
6        let export = if config.uses_type_interface { "" } else { "export " };
7        state.types.push('\n');
8        let name = self.ident.unraw().to_string();
9        let ty = crate::typescript::convert_type(&self.ty);
10        let comments = crate::utils::get_comments(self.attrs);
11        state.write_comments(&comments, 0);
12        state
13            .types
14            .push_str(format!("{export}type {name} = {ty}", name = name, ty = ty.ts_type).as_str());
15
16        state.types.push('\n');
17    }
18}