{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-1-3.html","result":{"data":{"markdownRemark":{"id":"8b9c0f93-5177-5584-a614-d8cc409a1882","excerpt":"Protected The new protected modifier in classes works like it does in familiar languages like C++, C#, and Java. A protected member of a class is visible only…","html":"<h2 id=\"protected\"><a href=\"#protected\" aria-label=\"protected permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Protected</h2>\n<p>The new <code>protected</code> modifier in classes works like it does in familiar languages like C++, C#, and Java. A <code>protected</code> member of a class is visible only inside subclasses of the class in which it is declared:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Thing {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">protected</span><span style=\"color: #000000\"> doSomething() { </span><span style=\"color: #008000\">/* ... */</span><span style=\"color: #000000\"> }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> MyThing </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Thing {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">public</span><span style=\"color: #000000\"> myMethod() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// OK, can access protected member from subclass</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.doSomething();</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> t = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> MyThing();</span>\n<span style=\"color: #000000\">t.doSomething(); </span><span style=\"color: #008000\">// Error, cannot call protected member from outside class</span></code></div></pre>\n<h2 id=\"tuple-types\"><a href=\"#tuple-types\" aria-label=\"tuple types permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tuple types</h2>\n<p>Tuple types express an array where the type of certain elements is known, but need not be the same. For example, you may want to represent an array with a <code>string</code> at position 0 and a <code>number</code> at position 1:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Declare a tuple type</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x: [string, number];</span>\n<span style=\"color: #008000\">// Initialize it</span>\n<span style=\"color: #000000\">x = [</span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #008000\">// Initialize it incorrectly</span>\n<span style=\"color: #000000\">x = [</span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// Error</span></code></div></pre>\n<p>When accessing an element with a known index, the correct type is retrieved:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">console.log(x[</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">].substr(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">)); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">console.log(x[</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">].substr(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">)); </span><span style=\"color: #008000\">// Error, 'number' does not have 'substr'</span></code></div></pre>\n<p>Note that in TypeScript 1.4, when accessing an element outside the set of known indices, a union type is used instead:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">x[</span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">] = </span><span style=\"color: #A31515\">'world'</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">console.log(x[</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">].toString()); </span><span style=\"color: #008000\">// OK, 'string' and 'number' both have toString</span>\n<span style=\"color: #000000\">x[</span><span style=\"color: #09835A\">6</span><span style=\"color: #000000\">] = </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error, boolean isn't number or string</span></code></div></pre>","headings":[{"value":"Protected","depth":2},{"value":"Tuple types","depth":2}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-1-3.html","title":"TypeScript 1.3"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-1-3.html","isOldHandbook":true}}}