feat: support typed message IDs#2503
Conversation
|
@mrmckeb is attempting to deploy a commit to the Crowdin Team on Vercel. A member of the Team first needs to authorize it. |
| export function plural( | ||
| value: number | string | LabeledExpression<number | string>, | ||
| options: ChoiceOptions | ||
| options: ChoiceOptions, |
There was a problem hiding this comment.
I investigated this change, which happened on save. This is the default in Prettier now, it's likely that this file hasn't been formatted for a while. I can revert if this change is an issue.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
andrii-bodnar
left a comment
There was a problem hiding this comment.
@mrmckeb thank you for the contribution! Please check the failed CI/CD pipeline.
Additionally, could we include a reference to the new guide in the Explicit vs Generated IDs article? This would improve the discoverability of the new feature.
|
Thanks @andrii-bodnar, I've just pushed up those changes. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #2503 +/- ##
===========================================
+ Coverage 76.66% 89.01% +12.35%
===========================================
Files 81 118 +37
Lines 2083 3315 +1232
Branches 532 978 +446
===========================================
+ Hits 1597 2951 +1354
+ Misses 375 329 -46
+ Partials 111 35 -76 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds an opt-in TypeScript mechanism for typed message IDs across Lingui packages, enabling autocomplete and compile-time validation when IDs are known ahead of time (via module augmentation).
Changes:
- Introduces
Registermodule-augmentation hook andMessageIdtype in@lingui/core, and wires it into core/react/macro typings. - Adds/extends type-tests to validate both the default (
MessageId = string) and augmented (union) behavior. - Documents the feature and adds it to the website sidebar.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| website/sidebars.ts | Adds “Typed Message IDs” to the Advanced docs sidebar. |
| website/docs/guides/typed-message-ids.md | New guide explaining how to opt into typed IDs via module augmentation. |
| website/docs/guides/explicit-vs-generated-ids.md | Adds a tip linking explicit IDs to the new typed-IDs guide. |
| tstyche.config.json | Expands test glob to include nested __typetests__ directories. |
| packages/react/src/TransNoContext.tsx | Narrows id props from string to MessageId. |
| packages/react/macro/index.d.mts | Updates macro prop types to use MessageId. |
| packages/core/tsconfig.json | Excludes the typed-ids typetest project from core’s tsc --noEmit run. |
| packages/core/src/index.ts | Re-exports MessageId and Register types from @lingui/core. |
| packages/core/src/i18n.ts | Adds Register/MessageId and applies MessageId to MessageDescriptor, events, and i18n._ overloads. |
| packages/core/macro/index.d.mts | Updates macro descriptor id typing to MessageId. |
| packages/core/typetests/typed-ids/tsconfig.json | New typetest tsconfig for the typed-ids augmentation scenario. |
| packages/core/typetests/typed-ids/lingui.d.ts | Provides module augmentation used by typed-ids typetests. |
| packages/core/typetests/typed-ids/index.tst.ts | Asserts typed-ids behavior (valid/invalid IDs) under augmentation. |
| packages/core/typetests/index.tst.ts | Asserts default behavior (MessageId resolves to string without augmentation). |
Comments suppressed due to low confidence (1)
packages/core/src/i18n.ts:78
MissingHandlerstill types the callback as(locale: string, id: string) => string, which prevents the new typed MessageId union from flowing into the publicmissinghandler API. Consider changing the callback signature to useid: MessageIdso consumers get the same compile-time validation/autocomplete when implementingmissinghandlers (it still resolves tostringwhen not augmented).
export type MissingMessageEvent = {
locale: Locale
id: MessageId
}
type MissingHandler = string | ((locale: string, id: string) => string)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
andrii-bodnar
left a comment
There was a problem hiding this comment.
Looks good to me! @timofei-iatsenko, please also take a look
|
Hey team, did you need anything from me on the PR at this stage? Thanks! |
|
Hi @mrmckeb, there are some conflicts in this PR, could you please rebase the branch? Please note, the |
|
Hi @andrii-bodnar, that's now done - I've rebased and pushed that up. Thanks again! |
Description
Adds support for optionally typed message IDs, for build systems where the message IDs are known ahead of time.
Types of changes
Fixes #2478
Checklist