jgolla / torn-api

MIT License
6 stars 5 forks source link

Type-safe response from multi() #311

Open smikula opened 2 years ago

smikula commented 2 years ago

I'd love to see a type-safe return value from the multi() method on various APIs. I know this is easier said than done — I can't think of a way to do it when passing an array of selection strings — but I there are other ways it could work. Something like:

await torn.user.multi().basic().battlestats().attacks().fetch();

Or:

await torn.user.multi(request => request.basic().battlestats().attacks());

Or with a little ingenuity I think even this could work:

await torn.user.basic().battlestats().attacks();

What do you think? If you're interested, I'd be up for working on a PR.

jgolla commented 2 years ago

@smikula, I would be interested in seeing your ideas. I added the multi calls as more of an afterthought, so they don't fit in as well as the other calls.

smikula commented 2 years ago

I have a proof of concept idea in this PR: https://github.com/jgolla/torn-api/pull/318

Alternately, you could just define a big return type from multi with all properties there but optional. That's a little annoying to work with as a consumer, but way easier for the library to code!