0

I have two json dicionary files, each with the same terms from two different languages.

{
   "Account" : {
      "AccountLockText" : "Your account is locked",
      "Login" : {
         "CreateAccount" : "Create an account",
         "LoginBtn" : "Login",
         "LoginHeader" : "Login"
      }
   }
}

And I have a dictionaries.d.ts:

declare module "dictionaries" {
    var Account: any;
}

To be called and used with typescript in my application. Sad part is that said file is empty, and I have no idea how to make that kind of connection.

Can someone help me with this?

2
  • so is it empty in what way? Commented Jan 25, 2018 at 15:47
  • The dictionaries.d.ts is empty apart the Account var. Theres no connection to the JSONs files. Commented Jan 25, 2018 at 16:03

1 Answer 1

2

I usually use a simple interface to describe a JSON message I'm getting back from a service call:

interface AccountData {
    Account: {
        AccountLockText: string;
        Login: {
            CreateAccount: string;
            LoginBtn: string;
            LoginHeader: string;
        }
    }
}

Here's an example of it in action (I'm just parsing a JSON string to show you how it adds the type information from the interface I use in the type annotation).

const data = `{
"Account" : {
    "AccountLockText" : "Your account is locked",
    "Login" : {
        "CreateAccount" : "Create an account",
        "LoginBtn" : "Login",
        "LoginHeader" : "Login"
    }
}
}`;

let result: AccountData = JSON.parse(data);

alert(result.Account.Login.CreateAccount);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.