How to add item dynamically to tuple in TypeScript?
<p>this question comes from <a href="https://stackoverflow.com/questions/37460704/how-to-push-item-to-string-in-typescript">How to push item to [string] in TypeScript</a></p>

<p>I want to create function like below.</p>

<pre><code>declare var sqlitePlugin:any;

getItems(options, callback) {

  var query: string = `SELECT item_code,
                        item_name
                      FROM items `;

  var param: [string];

  if (options['limit']) {
    var limit = options['limit'];
    query = query + " LIMIT ? ";
    param.push(String(limit));
  }

  if (options['offset']) {
    var offset = options['offset'];
    query = query + " OFFSET ? ";
    param.push(String(offset));
  }

  this.execQuery(query, param, (resultSet)=&gt;{
    this.items = [];
    for(let i = 0; i &lt; resultSet.rows.length; i++) {
      var item: Item = new Item();
      item.code = resultSet.rows.item(i).item_code;
      item.name = resultSet.rows.item(i).item_name;
      this.artists.push(item);
    }
    callback(this.items);
  } );
}
</code></pre>

<p>execQuery function needs to be set 'param' parameter as type of <code>[string]</code>.</p>

<p>So I declared 'param' tuple as <code>[string]</code>.</p>

<p>I want to change param tuple dynamically by <code>options['limit']</code> and <code>options['offset']</code> value.</p>

<p>But <code>param.push(String(limit));</code> fails because param is undefined so I tried <code>var param: [string] = [];</code> then syntax error occurred.</p>

<blockquote>
  <p>[ts] Type 'undefined[]' is not assignable to type '[string]'. Property '0' is missing in type 'undefined[]'.</p>
</blockquote>

<p>How do I solve this problem?</p>

<p>Thanks in advance.</p>