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

Typescript type for values provided to a message #886

Closed
einarlove opened this issue Feb 26, 2024 · 1 comment
Closed

Typescript type for values provided to a message #886

einarlove opened this issue Feb 26, 2024 · 1 comment
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@einarlove
Copy link

Is your feature request related to a problem? Please describe.

Given this example:

import { createTranslator } from "next-intl";

const messages = {
  basic: "Hello {name}!",
};

const t = createTranslator({ locale: "en", messages });

t("basic", { name: "world" }) // -> Hello world!
t("basic", { whatever: "world" }) // basic

It gives no error. I would want the values TranslationValues to be typed so that I can't pass anything, undefined or nothing at all.
The ICU message syntax does not allow optional values—as in render something else if no value—, so the translation function should not accept empty values.

Describe the solution you'd like

IntlMessages should know which values are included in the translated string and require them. Unsure of the complexity if it accept dates and the like, but a string | number should be good enough.

Describe alternatives you've considered

I want typescript error for the developer to catch the mistake, and the build to fail. So I've seen no solution for this.

@einarlove einarlove added enhancement New feature or request unconfirmed Needs triage. labels Feb 26, 2024
@amannn
Copy link
Owner

amannn commented Feb 26, 2024

Yep, I agree this would be helpful. This is a duplicate of #410.

@amannn amannn closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants