Reputation: 68740
I have a JavaScript object which stores a dictionary of words:
var Words = {};
Words.Account="Account";
Words.Account_Login="Account Login";
My Typescript definition looks like this:
declare class Words {
Account: string;
Account_Login: string;
}
To use it in my TypeScript I have to use "prototype". How can I not have to use prototype?
/// <reference path="../typings/words.d.ts" />
var abc = Words.prototype.Account_Login;
Upvotes: 0
Views: 87
Reputation: 68740
@tj-rockefeller is correct, I also found if I also just made the Words static, I could use them as intended.
var Words = {};
static Words.Account="Account";
static Words.Account_Login="Account Login";
Upvotes: 1
Reputation: 3733
In your example you are accessing Account_Login through the Words class as if it is a static variable.
If you are creating a class Words
then I would expect that you would be using it something like this:
var myWords = new Words();
var abc = myWords.Account_Login;
Maybe instead of a class definition you want to define an interface like the following:
declare interface IWords{
Account: string;
Account_Login: string;
}
Then taking your Words object make sure that you are using the interface that you defined
var myWords = Words as IWords;
var abc = myWords.Account_Login;
Upvotes: 1