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

Serde custom crate support #69

Closed
sinnrrr opened this issue Dec 29, 2021 · 3 comments
Closed

Serde custom crate support #69

sinnrrr opened this issue Dec 29, 2021 · 3 comments

Comments

@sinnrrr
Copy link

sinnrrr commented Dec 29, 2021

Hey! I've encountered the issue, that due to ts-rs does not support the serde crate feature, the program fails to compile.

Here is an example:

#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, TS)]
#[serde(crate = "near_sdk::serde")]
#[ts(export)]
pub struct SomeStruct {
    pub someProperty: Option<Base64VecU8>,
}

Error:

warning: failed to parse serde attribute
  | 
  | 
  | #[serde(crate = "near_sdk::serde")]
  | #[serde(crate = "near_sdk::serde")]
  | 
  = note: ts-rs failed to parse this attribute. It will be ignored.

error[E0277]: the trait bound `near_sdk::json_types::Base64VecU8: ts_rs::TS` is not satisfied

Thanks!

@NyxCode
Copy link
Collaborator

NyxCode commented Dec 29, 2021

What I think is going on here is much more mundane - Base64VecU8 just doesn't implement ts_rs::TS. You should try wrapping it in a newtype and implementing ts_rs::TS for that yourself, or use #[ts(type = "some typescript type")] to manually set the type of the field.

@sinnrrr
Copy link
Author

sinnrrr commented Dec 29, 2021

Thanks, @NyxCode! That did work, sorry for such a stupid issue.

@sinnrrr sinnrrr closed this as completed Dec 29, 2021
@NyxCode
Copy link
Collaborator

NyxCode commented Dec 29, 2021

absolutely no problem. feel free to open an other one if you hit an other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants