stream-chat-react icon indicating copy to clipboard operation
stream-chat-react copied to clipboard

BUG: streami18n.registerTranslation is too strictly typed

Open moekify opened this issue 3 years ago • 0 comments

Motivation I'm very frustrated by the registerTranslation function as it requires for it's language param a TranslationLanguage. As these are a group of stringLiterals it is actually not possible from a TypeScript point of view to add a new language. It will always error. Of course you can override it by casting, but that is not a solution, just a hack.

It looks like this bug was introduced in this commit where the required type was changed from just string to TranslationLanguage. https://github.com/GetStream/stream-chat-react/commit/3fc1b6e649d1077e87813929c6d1af6aea12a94c

Relevant lines: https://github.com/GetStream/stream-chat-react/blob/develop/src/i18n/Streami18n.ts#L640-L643

  registerTranslation(
    language: TranslationLanguages,
    translation: typeof enTranslations,
    customDayjsLocale?: Partial<ILocale>) {...}

Proposed solution I would probably just revert this back to string, because from my understanding any string can be used as a language identifier.

Acceptance Criteria I can actually register a new translation without getting a typescript error.

moekify avatar Mar 22 '22 11:03 moekify