Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm struggling with type definition for the error argument in handleTranslationError (onError callback).

Here is the function definition:

const handleTranslationError = (error: <missing_type>) => {
  if (!IS_DEVELOPMENT) {
    return
  }

  if (error instanceof MissingTranslationError) {
    const { code, descriptor } = error

    if (code === 'MISSING_TRANSLATION') {
      console.log(
        `%c⚠️ Missing translation for: ${
          descriptor?.defaultMessage || 'No defaultMessage defined'
        } (${descriptor?.id || 'No ID defined'})`,
        'color: orange'
      )
    }
  } else {
    console.error(error)
  }
}

and the provider:

const TranslationProvider: React.FC<TranslationProviderProps> = ({
  children,
}) => {
  const locale = useCurrentLocale()

  return (
    <IntlProvider
      messages={messages}
      locale={locale}
      defaultLocale={DEFAULT_LOCALE}
      fallbackOnEmptyString={true}
      onError={handleTranslationError}
    >
      {children}
    </IntlProvider>
  )
}

export default TranslationProvider

I can see that the error can be one of the following types:

MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError

, so I thought that I will declare my type, like so:

type IntlError = MissingTranslationError | MessageFormatError | MissingDataError | InvalidConfigError | UnsupportedFormatterError | FormatError

, but FormatError is not exported (all other ones are). Can anyone push me into the right direction, please?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.