typescript interface from typeof object

Viewed 100

We are using react-i18next for our translations and they allow you to override the types so you can use ts to verify your keys -- it works great except for 1 fact. Lets say we have this json object in common.json (aka common namespace)

{
   "first": "first",
   "nested": {
       "second": "Second"
    }
}

When you take the typeof that object and use it as the interface you get keys common:first and common:nested.second

It goes to dot notation once it his the second level. Is it possible to tell typescript to use : all the way down because all our translations are common:nested:second. We are fully prepared to change our translation -- but would be great to avoid it. Any help would be greatly appreciated.

Just for reference here is how we are supplying to the types to react-i18next (right from their docs)

import 'react-i18next';
declare module 'react-i18next' {
    export interface Resources {
        common: typeof import('./common.json');
    }
}
0 Answers
Related