Improved type-safety for t.raw() and improved autocomplete.
#2076
Replies: 1 comment 2 replies
-
|
Hey, thanks for raising this, your thoughtful comment and the demo repo!
This unfortunately has some downsides, like it not working well with features like these:
Due to this, the In your case, you could also implement the testimonials like this: <TestimonialCard
name={t('testimonials.items.john.name')}
text={t('testimonials.items.john.text')}
rating={5}
/>
<TestimonialCard
name={t('testimonials.items.jane.name')}
text={t('testimonials.items.jane.text')}
rating={5}
/>I know it might look almost too simple, but it really unlocks powerful optimizations like the ones mentioned above. To be honest, I'm thinking of deprecating I think the typical use cases for
These are my current thoughts, would be curious to hear your perspective on this! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a project where I wanted to create a type-safe component to display stuff based on the content of my translations file structure like this:
ChildKeySegmentst.rawmethod, that supports autocomplete for all the possible partial path segments, that may be passed, not only for the message keys, as the originalnext-intlAPI supports.t.rawto be correctly typed. So an object containing multiple messages should be correctly typed. The original API always returnedanysince it only supported message keys.I don't know, if there is a more elegant way to achieve this. I'd be happy to get some suggestions.
I also would like to know, why the typing of
t.rawis not more specific. Is this on purpose? If not, do you think, it might be a good idea to create an issue to improve the typing on this?I vibe coded a demo repository to showcase this. Please ignore the irrelevant slop in the repo. The solution itself was hand crafted by me in one of my projects. And to get a quick demo, I generated the project in this repo with firebase studio.
https://github.com/davemecha/next-intl-improved-typing-demo
I hope this is a good place for a discussion like this. I'm new to this project, so please close this topic if it's not matching well.
Beta Was this translation helpful? Give feedback.
All reactions