Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Type-safe ICU arguments #1499

Merged
merged 46 commits into from
Nov 7, 2024
Merged

feat!: Type-safe ICU arguments #1499

merged 46 commits into from
Nov 7, 2024

Conversation

amannn
Copy link
Owner

@amannn amannn commented Nov 1, 2024

{
  "UserProfile": {
    "title": "Hello {firstName}"
  }
}
function UserProfile({user}) {
  const t = useTranslations('UserProfile');
 
  // ✖️ Missing argument
  t('title');
 
  // ✅ Argument is provided
  t('title', {firstName: user.firstName});
}

Features

  • ICU arguments can now be validated with TypeScript (however, currently this is opt-in)

Breaking changes

  • undefined and null are no longer accepted as values for calls to t.

→ Proposed docs


Performance notes from a sample project

Scope:

  • 342 messages in total
  • 290 plain messages
  • 14 messages with simple params
  • 1 message with plural
  • 9 messages with date formatting
  • 20 messages with select
  • 8 messages with rich text

Check time from tsc --diagnostics:

  • No type augmentation for messages: ~2.20s
  • Type-safe keys: ~2.82s
  • Type-safe arguments: ~2.85s

This was observed on a MacBook Pro 2019 (Intel).


Resolves #410

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 7, 2024 2:23pm
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 7, 2024 2:23pm
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 7, 2024 2:23pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant