Skip to content

How to use genertic type with commond? #9554

Answered by FabianLars
Hellager asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, this is indeed not possible. Rust needs to know the actual type behind the generic at compile time. So in rust you'd need a trait and have multiple structs that implement that trait and resemble your ts types. Without generics you can also just use an enum with the different fields (must implement serde::Deserialize correctly).
Edit: Now that i think about it, iirc tauri::commands don't support generics at all.

If you just want something working quickly you can use serde_json::Value which is basically a dynamic object. Then you'll have to do the type checking at runtime yourself (checking the object properties).

Replies: 1 comment 1 reply

Comment options

FabianLars
Apr 23, 2024
Maintainer Sponsor

You must be logged in to vote
1 reply
@Hellager
Comment options

Answer selected by Hellager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants