ts-rs
ts-rs copied to clipboard
proof-of-concept of type overrides using the CLI
This PR implements a POC of how we could implement type overrides using the CLI.
I am in no way sure that this is the right way to implement this. Besides the implementation (are environment variables really the right choice here?), these overrides would apply to the whole dependency chain. That might be the right behavior, but I'm not sure.
I am in no way sure that this is the right way to implement this. [...] (are environment variables really the right choice here?)
I like this implementation, and I'm not sure there even is another option to get cargo test to read the overrides without environment variables
Besides the implementation [...], these overrides would apply to the whole dependency chain. That might be the right behavior, but I'm not sure.
I think this is the right behavior. If, for example, the user wants u64 to be treated as number, they probably want it like that all the way up the chain
Hey @NyxCode! Is there anything else you'd like to do before merging this into the cli branch?
Hey @NyxCode, one question I have about this: why do we need one env variable for each type override? Couldn't a single env variable work, like TS_RS_INTERNAL_OVERRIDE=String,string;i64,number (ofc the separators I used here are arbitrary and can be replaced by anything else, as long as neither TS or Rust consider it a valid character inside identifiers)
Alternatively, we could make ts-rs itself read the overrides from the file and have an env variable determine the path it reads from, though that would require adding a toml parser to ts-rs as well as the CLI, which is not ideal
Yeah, I just did what seemed the most straight-forward here. Both reading them from a file (& caching it in a global?) and merging them into one environment variable are certainly possible.