Skip to content

Type: String | LanguageMessage is not assignable to string #1

@amirnsamimi

Description

@amirnsamimi

https://github.com/WebDevSimplified/intl-crash-course/blob/51d1f91b71c17d698a03978fd963c15ff0f6c964/src/i18n/lib/init.ts#L83C3-L83C39

Hey WebDevSimplified,

I was implementing your stuff on my project and faced this issue.

TS2344: Type
NormalizedTranslationAtKey<TranslationAtKeyWithParams<LanguageMessages, S>>[0]
does not satisfy the constraint string
Type
NormalizedTranslationAtKey<S extends string | number ? LanguageMessages | I18nMessage : never>[0]
is not assignable to type string
Type string | LanguageMessages is not assignable to type string
Type LanguageMessages is not assignable to type strin

luckily, I solved it with adding extra code at end ofNormalizedTranslationAtKeyWithParams enforcing to accept possible types but hopefully is has a better solution.

type NormalizedTranslationAtKeyWithParams<Key extends string> = NormalizedTranslationAtKey<
    TranslationAtKeyWithParams<RegisteredTranslations, Key> &
        (string | ReturnType<typeof defineTranslation>)
>

Thanks for you great solution,
br,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions