ts-rs icon indicating copy to clipboard operation
ts-rs copied to clipboard

proof-of-concept of type overrides using the CLI

Open NyxCode opened this issue 1 year ago • 3 comments
trafficstars

This PR implements a POC of how we could implement type overrides using the CLI.

NyxCode avatar Jun 21 '24 02:06 NyxCode

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.

NyxCode avatar Jun 21 '24 02:06 NyxCode

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

gustavo-shigueo avatar Jun 26 '24 17:06 gustavo-shigueo

Hey @NyxCode! Is there anything else you'd like to do before merging this into the cli branch?

gustavo-shigueo avatar Jul 02 '24 16:07 gustavo-shigueo

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

gustavo-shigueo avatar Feb 21 '25 16:02 gustavo-shigueo

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.

NyxCode avatar Feb 24 '25 01:02 NyxCode