Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Thanks. I'm not going to be very specific here because I'm too lazy to dig into that giant type, but if they want that method implementation to work without type assertions then the `add` method would need to be typed as an assertion function[1] so the type system can understand that it narrows its argument[2].

Here's an example: https://tsplay.dev/w8y9PN

[1]: https://www.typescriptlang.org/docs/handbook/release-notes/t...

[2]: Doing this isn't safe anyway because it mutates an object in a type-relevant way while there may other variables referring to it (the safe thing to do is return a new `Elysia` instance from `get`), but that's beside the point.



That's really interesting with the assertion function, I've not seen that done much, thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: