H
Hono6mo ago
Arjun

Can someone explain why types aren't inferred

If I use this code then the types arent inferred whereas with the code in the second image I can
No description
No description
9 Replies
Nico
Nico6mo ago
What’s the difference between the code? It looks the same
Mickaël
Mickaël6mo ago
The difference is that on the left, he doesn't chain methods In my case too, without chaining, type inference doesn't work
Nico
Nico6mo ago
I did some research on this here is what I found "TypeScript infers and preserves type information through method chaining directly at assignment versus modifying an instance with method calls in subsequent lines." So pretty much when dealing with a class TS takes the types of the class when it is initiated. When you chain onto it's appened to the class. When you call it later it does not modify the types that were inferred. I belive this is why when using RPC all the routes have to be chained
Mickaël
Mickaël6mo ago
Yes, and it's a problem in the sense that the documentation is full of examples that don't use chaining. I personally chose to chain all the methods on my project, but I have to admit that this has an impact on readability. Here's a related issue: https://github.com/honojs/hono/issues/2120#issuecomment-1917847801
GitHub
RPC Client isn't compatible with app.route() · Issue #2120 · honojs...
What version of Hono are you using? 3.12.8 What runtime/platform is your app running on? Bun What steps can reproduce the bug? // routes/routerA.ts import { Hono } from "hono"; import { z...
Nico
Nico6mo ago
I think that is why Elysia requires chaining or at least only shows docs with chaning last time I looked
Mickaël
Mickaël6mo ago
Yes if it's a Typescript limitation then you have to live with it ^^
Nico
Nico6mo ago
I know typescript has a big update coming, I don't know if this is something that they will solve
Mickaël
Mickaël6mo ago
Do you think this kind of functionality would be added via Typescript 5.5 - Inferred Type Predicates ?
Daniel Rosenwasser
TypeScript
Announcing TypeScript 5.5 RC - TypeScript
Today we are excited to announce the availability of the release candidate of TypeScript 5.5. To get started using the RC, you can get it through NuGet, or through npm with the following command: npm install -D typescript@rc Here’s a quick list of what’s new in TypeScript 5.5!
Nico
Nico6mo ago
I was just looking through it, I doesn't appear so But there are a few other type inference issues they are fixing
Want results from more Discord servers?
Add your server