birpc icon indicating copy to clipboard operation
birpc copied to clipboard

Unable to use only one type parameter

Open iSuslov opened this issue 1 month ago • 1 comments

Describe the bug

Hi, thanks for this awesome library. I don't know if it worked in previous versions of typescript, but when I pass only one type argument I get an error:

import { createBirpc } from "birpc";
const serverFunctions = {
  hiFromServer(name: string) {
    return `Hi ${name} from server`;
  },
};
const clientFunctions = {
  hiFromClient(name: string) {
    return `Hi ${name} from client`;
  },
};

const birpc =  createBirpc<typeof serverFunctions>(
    clientFunctions,  // <--- Error
    {
    on(fn) {

    },
    post(data, ...extras) {

    },
  });
Argument of type '{ hiFromClient(name: string): string; }' is not assignable to parameter of type 'Record<string, never>'.
  Property 'hiFromClient' is incompatible with index signature.
    Type '(name: string) => string' is not assignable to type 'never'. TS(2345)

So it basically can't infer the right type when you set default generic value to Record<string, never>.

So examples from README doesn't work.

Fix

Changing generic parameters default type here and in relevant places should fix it. It works with any of this constraints instead:

LocalFunctions extends object = Record<string, unknown>
LocalFunctions extends object = Record<string, any>
LocalFunctions extends object = object

Reproduction

Provided above

System Info

TypeScript version 5.9.3
birpc 2.7.0

Used Package Manager

npm

Validations

  • [x] Follow our Code of Conduct
  • [x] Read the Contributing Guide.
  • [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [x] The provided reproduction is a minimal reproducible of the bug.

Contributions

  • [x] I am willing to submit a PR to fix this issue
  • [x] I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)

iSuslov avatar Nov 08 '25 05:11 iSuslov

PR welcome! Thanks!

antfu avatar Nov 08 '25 08:11 antfu