I am pretty new to TypeScript.
I have created a class with some private fields. When I attempt to assign a value to one of the fields in an anonymous callback function within a class method I get the error ...
(TS) Cannot Find the name '_tokens'
I suspect that there is a scoping issue but from my understanding of JavaScript this should not be a problem. I am not sure how to fix it. Any ideas?
See .. "populateTokens()" method for error.
class SingleSignOn {
private _appTokensURL: string = "/api/IFSessionCache/Auth/";
private _tokens: string[];
/**
* Initialize an instance of the SingleSignOn class to manage the permissions for the
* application associated with the application.
*/
constructor() {
this.populateTokens();
};
/**
* Gets a list of permissions tokens associated with the currently logged on user for
* the application.
*/
private getApplicationTokens(): Q.IPromise<{}> {
return Unique.AJAX.Get(this._appTokensURL, null, ENUMS.AjaxContentTypes.JSON);
};
private populateTokens () {
this.getApplicationTokens().then(
function (data) {
_tokens = <string[]>data; // (TS) Cannot find name "_tokens"
});
};
};