Create a dynamic variable reference in Typescript
<p>Thanks ahead of time, to anyone who helps. :)</p>

<p>This may seem a simple answer to those who are experienced, but I have scoured the internet as well as a couple of reference books, and not found a straight forward answer to this question, so hopefully it may be of help to others as well.</p>

<p>I'm currently transitioning from Actionscript to Typescript, and have a reasonable amount of experience with vanilla Javascript, so to put it simply in Javascript terms, if I wanted to dynamically reference a variable, I could simply use something like this:</p>

<pre><code>var myTextA = "Hello!";
var myTextB = "Goodbye!";
var textList = ["A", "B"];
console.log("I want to say " + this["myText" + textList[0]]);
</code></pre>

<p>The result would of course be: "I want to say Hello!"</p>

<p>In Typescript this does not appear to be possible with <em>private variables</em> in a class, and results in the following TSC error:</p>

<pre><code>"Index signature of object type implicitly has an 'any' type."
</code></pre>

<p>As far as I can gather, typescript expects me to declare the variable type in some way, within the dynamic construct, however I cannot find any clear reference on how to do this.</p>

<p>For my own purposes, to put this in context, I am working on a project where I need to loop through a series of paired variables that all have the same beginning, but slightly different endings so simply putting the variables themselves in an array is not an option (Or would be a messy solution, at any rate).</p>

<p>For example:</p>

<pre><code>var myVar1a, myVar1b, myVar2a, myVar2b etc...
</code></pre>

<p>So in the loop, I would want to refer to both a and b of each:</p>

<pre><code>console.log(this["myVar" + (i+1) + "a");
console.log(this["myVar" + (i+1) + "b");
</code></pre>

<p>Any help is much appreciated!!</p>