1

in my React application I have a few types:

export interface LocaleData {

    languages: Languages, // shows error here
    [stringKey: string]: Strings
}

export interface Languages {
    [languageKey: string]: string
}

export interface Strings {
    login: {
        headerGreeting: string,
        firstStepGeneralMessage: string,
        cellNumber: string,
        cellNumberError: string,
        areaCodePref: string,
        canContinue: string,
        signoutAlertTitle: string,
        signoutAlertContent: string,
        signoutPositiveButton: string
    },
////
}

Now, the code works and all, but I get an error that says:

Property 'languages' of type 'Languages' is not assignable to string index type 'Strings'.

I can't figure out what's wrong with the provided code and how to avoid this error?

Keselme
  • 3,779
  • 7
  • 36
  • 68
  • Does this answer your question? [TypeScript Interface Array Type error TS2411](https://stackoverflow.com/questions/33818178/typescript-interface-array-type-error-ts2411) – Nino Filiu Mar 08 '21 at 15:30
  • 1
    This should help you https://stackoverflow.com/questions/61431397/how-to-define-typescript-type-as-a-dictionary-of-strings-but-with-one-numeric-i – captain-yossarian from Ukraine Mar 08 '21 at 19:02
  • This is a hard pattern to deal with and honestly I would recommend moving all of your strings to a sub-property. `export interface LocaleData { languages: Languages; strings: { [stringKey: string]: Strings; } }` – Linda Paiste Mar 08 '21 at 20:08

0 Answers0