oscartbeaumont / rspc

A framework for building typesafe web backends in Rust
https://rspc.dev
MIT License
1.1k stars 50 forks source link

addSubscription TS signature is incorrect #186

Closed campbellcole closed 11 months ago

campbellcole commented 12 months ago

The signature for the client.addSubscription function cause valid parameters to error out, and causes "valid" parameters to throw runtime errors.

Given the following subscription in the Router:

router
    .subscription("logs", |s| {
        s(|_, test: ()| LogExportLayer::add_client())
    });

the following TS will throw a TypeScript error:

client.addSubscription(["logs"], { ... });
// Argument of type '["logs"]' is not assignable to parameter of type '["logs", []]'.

and if the () type is replaced with, say, String: Argument of type '["logs"]' is not assignable to parameter of type '["logs", [string]]'.

The fix is relatively simple and I will submit a pull request shortly.

oscartbeaumont commented 11 months ago

Thanks! Should be fixed!