Skip to content

Is there a nice way to combine a formatter with a type? #643

Answered by ivanhofer
chriscoomber asked this question in Q&A
Discussion options

You must be logged in to vote

All types are being generated by reading your BaseLocale file. If you specify a formatter there, then it get's added to the Formatters type. The types of the parameter of those fmatter functions also need to be read using the type information you give when applying a formatter i one of your translations.
If you don't specify a type then the input to your formatter function will be unknown. But because it get's used in a plural rule, typesafe-18n will narroẇ down the type to string | number | boolean which are the only allwed input types to the Intl.PluralRules.

If ou don't want to specify the type manually, you can write your formatter function like this:

export const initFormatters: Form…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@chriscoomber
Comment options

@ivanhofer
Comment options

Answer selected by ivanhofer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants