You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently searching for a way to map TypeScript branded types, like https://github.com/kourge/ts-brand cleanly using specta. My current (flawed) approach is:
Tracked in #17. I intend to support this in Specta v2 (mostly to avoid the need for Specta v3) but it's worth noting Serde doesn't support const parameters.
need to remove export Type Brand
It's hacky but this is possible (and sadly is something we do in Spacedrive).
If you're using 2.0.0-rc.x releases you will need to use main for (cab26b1) or if your using the crates.io releases the TypeMap (previously TypeDefs) was just a BTreeMap so you can do whatever.
Getting access to the TypeMap it's not super easy right now, you would need to copy the implementation of either specta::ts::export or specta::ts::inline into your own crate based on which one you are using.
This is the sorta feature that probably needs its own higher-level abstraction outside of the specta core crate.
need to manually add import header for import {Brand} from ts-brand; (not that bad)
Right now you would have to do this manually after Specta runs. Tauri Specta has a header propery which is set by the user and is injected at the start of the file. This is something Specta should probs have too which was an oversight.
I'm honestly not sure we have a way to express this at the moment. It could be done with #110 or #17 but neither are supported at the moment and both have unanswered questions about exactly how I would want them to work.
A correction to the bit about the header property only matters when using the export feature flag. The normal specta::ts::* stuff doesn't suffer that problem because it's on you to deal with the file writing.
I am currently searching for a way to map TypeScript branded types, like https://github.com/kourge/ts-brand cleanly using specta. My current (flawed) approach is:
Which reduces to:
Now, this is not ideal due to several factors:
export Type Brand<T>
import {Brand} from ts-brand;
(not that bad)adt_const_params
, which is incomplete.What I would love (in a perfect world) would be something similar to:
How would I approach this problem? Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: