- 1 year ago 75
Javascript Question

Typescript typings definition of a property

Newbie question

I have a Javascript object which stores a dictionary of words:

var Words = {};
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;

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download