Skip to content

Unable to use only one type parameter #32

@iSuslov

Description

@iSuslov

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

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

Contributions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions