nanostores/query

ts-rest integration possibility

Amuleus opened this issue · 1 comments

Hello,

I'm already incorporating nanostores for outside of components state management.
It's really exciting and usable to have that small size libs. Big thanks for that!

The only thing preventing to use nanostores/query is ability to integrate with modern type-safe API approaches.

I'm aware of dificulties of integration with trpc, but is possible to use integrate nanostores/query with ts-rest?

This is example similar integration of react-query (which I wan to replace with nanostores/query) https://github.com/ts-rest/ts-rest/tree/main/libs/ts-rest/react-query/src/lib

dkzlv commented

I'm aware of dificulties of integration with trpc, but is possible to use integrate nanostores/query with ts-rest?

I believe ts-rest has the same problems as trpc. They too have extremely convoluted and complex APIs, and I don't think we'll have a bandwidth to integrate with them completely.

But ts-rest is a much simpler in a sense that it's not a whole-ass RPC thing. I don't have any specific experience with it, but I believe you can use ts-rest with basic REST-api, which means you can omit using the router on the client and instead infer types based on the contract type and pass those types to fetcher/mutator stores (e.g., createFetcherStore<ClientInferResponseBody<typeof contract.getPosts, 200>>(...)). This way the response body for 200 or for any error is strictly typed, and the only place where you lose e2e typing is the path to API endpoint, but I hope that's tolerable (those don't change very often).

I'll close it for now, but if there are any nanoquery specific questions to follow up on, feel free to ask them here!