RPC InferRequestType with Param gives "Property is incompatible with index signature."

I've been learning Hono, been having a great time with it as it solves my biggest grief with NextJS API routes! I've run into some problems with type inference. I have two path params, and would like to be able to simply pass {param: {storeId, billboardId}} to the request call but Typescript complains with the message below [and in screenshot]. Am I using something the wrong way in Hono ? is there a better a way of solving this ? Any feedback welcome, and thanks for looking! PS: I'm aware the mutateFn looks messy at the start, that's me trying to figure out how to best deconstruct the params for now. Full gist with single file repro: https://gist.github.com/sterlinghagoromo/c822866ddeab8b7e46a1c8e9e34e6028#file-single_file_repro-ts-L49 Text version of the error in the screenshot:
TS2345: Argument of type
{
param: {
storeId: string | undefined;
billboardId: string | undefined;
};
}
{
param: {
storeId: string | undefined;
billboardId: string | undefined;
};
}
is not assignable to parameter of type
{
param: {
storeId?: string | undefined;
billboardId?: string | undefined;
} & {
[x: string]: string;
[x: number]: string;
[x: symbol]: string;
};
}
{
param: {
storeId?: string | undefined;
billboardId?: string | undefined;
} & {
[x: string]: string;
[x: number]: string;
[x: symbol]: string;
};
}
Types of property param are incompatible. Type '{ storeId: string | undefined; billboardId: string | undefined; }' is not assignable to type '{ storeId?: string | undefined; billboardId?: string | undefined; } & { [x: string]: string; [x: number]: string; [x: symbol]: string; }'. Type '{ storeId: string | undefined; billboardId: string | undefined; }' is not assignable to type '{ [x: string]: string; [x: number]: string; [x: symbol]: string; }'. Property storeId is incompatible with index signature. Type string | undefined is not assignable to type string Type undefined is not assignable to type string
Gist
Hono RPC InferRequestType with Param gives "Property is compatible ...
Hono RPC InferRequestType with Param gives "Property is compatible with index signature" - single_file_repro.ts
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server