(ty: &syn::Type)
| 172 | } |
| 173 | |
| 174 | pub fn convert_type(ty: &syn::Type) -> TsType { |
| 175 | match ty { |
| 176 | syn::Type::Reference(p) => convert_type(&p.elem), |
| 177 | syn::Type::Path(p) => { |
| 178 | let segment = p.path.segments.last().unwrap(); |
| 179 | let identifier = segment.ident.to_string(); |
| 180 | |
| 181 | if let Ok(ts_type) = try_match_ident_str(&identifier) { |
| 182 | ts_type.into() |
| 183 | } else if let Ok(ts_type) = try_match_with_args(&identifier, &segment.arguments) { |
| 184 | ts_type |
| 185 | } else if let Ok(ts_type) = extract_custom_type(segment) { |
| 186 | ts_type |
| 187 | } else { |
| 188 | "unknown".to_owned().into() |
| 189 | } |
| 190 | } |
| 191 | syn::Type::Tuple(t) => { |
| 192 | let types = t |
| 193 | .elems |
| 194 | .iter() |
| 195 | .map(convert_type) |
| 196 | .map(|ty| { |
| 197 | if ty.is_optional { |
| 198 | format!("{} | undefined", ty.ts_type) |
| 199 | } else { |
| 200 | ty.ts_type |
| 201 | } |
| 202 | }) |
| 203 | .collect::<Vec<String>>() |
| 204 | .join(", "); |
| 205 | |
| 206 | TsType { |
| 207 | ts_type: format!("[{types}]"), |
| 208 | is_optional: false, |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | _ => "unknown".to_owned().into(), |
| 213 | } |
| 214 | } |
no test coverage detected