H
Hono4mo ago
[DQ] Swat

Type inference breaks after upgrading hono

(Example image at the end of post) The following code relies on type inference to work. When upgrading from Hono version 4.2.2 to 4.4.3 on both the frontend and backend, the following code broke. 1. I do an rpc fetch like this:
const request = client.api.song[":id"].skips.$get({
param: { id: id.toString() },
header: { "authorization": `OAuth ${getAuthToken()}` }
});

const response = await handleRequest(request);
const request = client.api.song[":id"].skips.$get({
param: { id: id.toString() },
header: { "authorization": `OAuth ${getAuthToken()}` }
});

const response = await handleRequest(request);
2. Then I pass the request promise to a function which handles the request
//handleRequest.ts
export default async function handleRequest<T>(request: Promise<ClientResponse<T>>): Promise<RequestWithResolveData<T>> {
const response = await request;

if (response.ok) {
return {
code: response.status,
data: response,
success: true
};

...
}
}
//handleRequest.ts
export default async function handleRequest<T>(request: Promise<ClientResponse<T>>): Promise<RequestWithResolveData<T>> {
const response = await request;

if (response.ok) {
return {
code: response.status,
data: response,
success: true
};

...
}
}
Then I check if the request was successful and fail to read the data. All the type inference stays until I call .json().
if (!response.success) {
return {
errors: response.errors,
success: false
};
}

/*
Object is of type unknown
(method) ClientResponse<{ name: string; skip_id: number; start: number; end: number; url: string; category: ESkipCategory; picture: string; }[], StatusCode, string>.json(): Promise<unknown>
*/
const skips = (await response.data.json()).map(networkSongToSongAdapter);
if (!response.success) {
return {
errors: response.errors,
success: false
};
}

/*
Object is of type unknown
(method) ClientResponse<{ name: string; skip_id: number; start: number; end: number; url: string; category: ESkipCategory; picture: string; }[], StatusCode, string>.json(): Promise<unknown>
*/
const skips = (await response.data.json()).map(networkSongToSongAdapter);
What could be causing this?
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server