Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generic impl #281

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Fixes

- Macro expansion for types with generic parameters now works without the `TS` trait in scope ([#281](https://github.com/Aleph-Alpha/ts-rs/pull/281))

# v8.0.0

### Breaking
Expand Down
3 changes: 1 addition & 2 deletions macros/src/attr/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::collections::HashMap;
use syn::{parse_quote, Attribute, Ident, Path, Result, Type, WherePredicate};

use super::{parse_assign_from_str, parse_bound, parse_concrete};
use crate::attr::EnumAttr;
use crate::{
attr::{parse_assign_str, Inflection, VariantAttr},
attr::{parse_assign_str, EnumAttr, Inflection, VariantAttr},
utils::{parse_attrs, parse_docs},
};

Expand Down
3 changes: 2 additions & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl DerivedTS {
/// impl ts_rs::TS for B { /* .. */ }
/// ```
fn generate_generic_types(&self, generics: &Generics) -> TokenStream {
let crate_rename = &self.crate_rename;
let generics = generics
.type_params()
.filter(|ty| !self.concrete.contains_key(&ty.ident))
Expand All @@ -154,7 +155,7 @@ impl DerivedTS {
write!(f, "{:?}", self)
}
}
impl TS for #generics {
impl #crate_rename::TS for #generics {
type WithoutGenerics = #generics;
fn name() -> String { stringify!(#generics).to_owned() }
fn inline() -> String { panic!("{} cannot be inlined", Self::name()) }
Expand Down
4 changes: 2 additions & 2 deletions ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ pub use ts_rs_macros::TS;
pub use crate::export::ExportError;
use crate::typelist::TypeList;

#[cfg(feature = "serde-json-impl")]
mod serde_json;
#[cfg(feature = "chrono-impl")]
mod chrono;
mod export;
#[cfg(feature = "serde-json-impl")]
mod serde_json;
pub mod typelist;

/// A type which can be represented in TypeScript.
Expand Down
6 changes: 6 additions & 0 deletions ts-rs/tests/generic_without_import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(dead_code)]

#[derive(ts_rs::TS)]
struct Test<T> {
field: T,
}
2 changes: 1 addition & 1 deletion ts-rs/tests/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ fn inlined_value() {
#[derive(TS)]
#[ts(export, export_to = "serde_json_impl/")]
struct Simple {
json: serde_json::Value
json: serde_json::Value,
}
Loading