{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-2-6.html","result":{"data":{"markdownRemark":{"id":"665aeb67-ad0d-5db7-9d48-4eef1b1a80b1","excerpt":"Strict function types TypeScript 2.6 introduces a new strict checking flag, --strictFunctionTypes.\nThe --strictFunctionTypes switch is part of the --strict…","html":"<h2 id=\"strict-function-types\"><a href=\"#strict-function-types\" aria-label=\"strict function 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>Strict function types</h2>\n<p>TypeScript 2.6 introduces a new strict checking flag, <code>--strictFunctionTypes</code>.\nThe <code>--strictFunctionTypes</code> switch is part of the <code>--strict</code> family of switches, meaning that it defaults to on in <code>--strict</code> mode.\nYou can opt-out by setting <code>--strictFunctionTypes false</code> on your command line or in your tsconfig.json.</p>\n<p>Under <code>--strictFunctionTypes</code> function type parameter positions are checked <em>contravariantly</em> instead of <em>bivariantly</em>.\nFor some background on what variance means for function types check out <a href=\"https://www.stephanboyer.com/post/132/what-are-covariance-and-contravariance\">What are covariance and contravariance?</a>.</p>\n<p>The stricter checking applies to all function types, <em>except</em> those originating in method or constructor declarations.\nMethods are excluded specifically to ensure generic classes and interfaces (such as <code>Array&#x3C;T></code>) continue to mostly relate covariantly.</p>\n<p>Consider the following example in which <code>Animal</code> is the supertype of <code>Dog</code> and <code>Cat</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> f1: (x: Animal) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void;</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> f2: (x: Dog) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void;</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> f3: (x: Cat) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void;</span>\n<span style=\"color: #000000\">f1 = f2;  </span><span style=\"color: #008000\">// Error with --strictFunctionTypes</span>\n<span style=\"color: #000000\">f2 = f1;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">f2 = f3;  </span><span style=\"color: #008000\">// Error</span></code></div></pre>\n<p>The first assignment is permitted in default type checking mode, but flagged as an error in strict function types mode.\nIntuitively, the default mode permits the assignment because it is <em>possibly</em> sound, whereas strict function types mode makes it an error because it isn’t <em>provably</em> sound.\nIn either mode the third assignment is an error because it is <em>never</em> sound.</p>\n<p>Another way to describe the example is that the type <code>(x: T) => void</code> is <em>bivariant</em> (i.e. covariant <em>or</em> contravariant) for <code>T</code> in default type checking mode, but <em>contravariant</em> for <code>T</code> in strict function types mode.</p>\n<h5 id=\"example\"><a href=\"#example\" aria-label=\"example 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Comparer&lt;T&gt; {</span>\n<span style=\"color: #000000\">    compare: (a: T, b: T) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> number;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> animalComparer: Comparer&lt;Animal&gt;;</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> dogComparer: Comparer&lt;Dog&gt;;</span>\n\n<span style=\"color: #000000\">animalComparer = dogComparer;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">dogComparer = animalComparer;  </span><span style=\"color: #008000\">// Ok</span></code></div></pre>\n<p>The first assignment is now an error. Effectively, <code>T</code> is contravariant in <code>Comparer&#x3C;T></code> because it is used only in function type parameter positions.</p>\n<p>By the way, note that whereas some languages (e.g. C# and Scala) require variance annotations (<code>out</code>/<code>in</code> or <code>+</code>/<code>-</code>), variance emerges naturally from the actual use of a type parameter within a generic type due to TypeScript’s structural type system.</p>\n<h5 id=\"note\"><a href=\"#note\" aria-label=\"note 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>Note</h5>\n<p>Under <code>--strictFunctionTypes</code> the first assignment is still permitted if <code>compare</code> was declared as a method.\nEffectively, <code>T</code> is bivariant in <code>Comparer&#x3C;T></code> because it is used only in method parameter positions.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Comparer&lt;T&gt; {</span>\n<span style=\"color: #000000\">    compare(a: T, b: T): number;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> animalComparer: Comparer&lt;Animal&gt;;</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> dogComparer: Comparer&lt;Dog&gt;;</span>\n\n<span style=\"color: #000000\">animalComparer = dogComparer;  </span><span style=\"color: #008000\">// Ok because of bivariance</span>\n<span style=\"color: #000000\">dogComparer = animalComparer;  </span><span style=\"color: #008000\">// Ok</span></code></div></pre>\n<p>TypeScript 2.6 also improves type inference involving contravariant positions:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> combine&lt;T&gt;(...funcs: ((x: T) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void)[]): (x: T) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> x </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">for</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> f </span><span style=\"color: #0000FF\">of</span><span style=\"color: #000000\"> funcs) f(x);</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> animalFunc(x: Animal) {}</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> dogFunc(x: Dog) {}</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> combined = combine(animalFunc, dogFunc);  </span><span style=\"color: #008000\">// (x: Dog) =&gt; void</span></code></div></pre>\n<p>Above, all inferences for <code>T</code> originate in contravariant positions, and we therefore infer the <em>best common subtype</em> for <code>T</code>.\nThis contrasts with inferences from covariant positions, where we infer the <em>best common supertype</em>.</p>\n<h2 id=\"cache-tagged-template-objects-in-modules\"><a href=\"#cache-tagged-template-objects-in-modules\" aria-label=\"cache tagged template objects in modules 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>Cache tagged template objects in modules</h2>\n<p>TypeScript 2.6 fixes the tagged string template emit to align better with the ECMAScript spec.\nAs per the <a href=\"https://tc39.github.io/ecma262/#sec-gettemplateobject\">ECMAScript spec</a>, every time a template tag is evaluated, the <em>same</em> template strings object (the same <code>TemplateStringsArray</code>) should be passed as the first argument.\nBefore TypeScript 2.6, the generated output was a completely new template object each time.\nThough the string contents are the same, this emit affects libraries that use the identity of the string for cache invalidation purposes, e.g. <a href=\"https://github.com/PolymerLabs/lit-html/issues/58\">lit-html</a>.</p>\n<h5 id=\"example-1\"><a href=\"#example-1\" aria-label=\"example 1 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> id(x: TemplateStringsArray) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> x;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> templateObjectFactory() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">id`hello world`</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> result = templateObjectFactory() === templateObjectFactory(); </span><span style=\"color: #008000\">// true in TS 2.6</span></code></div></pre>\n<p>Results in the following generated code:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #A31515\">\"use strict\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> __makeTemplateObject = (</span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\"> && </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.__makeTemplateObject) || </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> (cooked, raw) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (Object.defineProperty) { Object.defineProperty(cooked, </span><span style=\"color: #A31515\">\"raw\"</span><span style=\"color: #000000\">, { value: raw }); } </span><span style=\"color: #0000FF\">else</span><span style=\"color: #000000\"> { cooked.raw = raw; }</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> cooked;</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> id(x) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> x;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> _a;</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> templateObjectFactory() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> id(_a || (_a = __makeTemplateObject([</span><span style=\"color: #A31515\">\"hello world\"</span><span style=\"color: #000000\">], [</span><span style=\"color: #A31515\">\"hello world\"</span><span style=\"color: #000000\">])));</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> result = templateObjectFactory() === templateObjectFactory();</span></code></div></pre>\n<blockquote>\n<p>Note: This change brings a new emit helper, <code>__makeTemplateObject</code>;\nif you are using <code>--importHelpers</code> with <a href=\"https://github.com/Microsoft/tslib\"><code>tslib</code></a>, an updated to version 1.8 or later.</p>\n</blockquote>\n<h2 id=\"localized-diagnostics-on-the-command-line\"><a href=\"#localized-diagnostics-on-the-command-line\" aria-label=\"localized diagnostics on the command line 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>Localized diagnostics on the command line</h2>\n<p>TypeScript 2.6 npm package ships with localized versions of diagnostic messages for 13 languages.\nThe localized messages are available when using <code>--locale</code> flag on the command line.</p>\n<h5 id=\"example-2\"><a href=\"#example-2\" aria-label=\"example 2 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>Example</h5>\n<p>Error messages in Russian:</p>\n<pre class=\"shiki\"><div class=\"language-id\">sh</div><div class='code-container'><code><span style=\"color: #000000\">c:\\ts&gt;tsc --v</span>\n<span style=\"color: #000000\">Version 2.6.0-dev.20171003</span>\n\n<span style=\"color: #000000\">c:\\ts&gt;tsc --locale ru --pretty c:\\test\\a.ts</span>\n\n<span style=\"color: #000000\">../test/a.ts(1,5): error TS2322: Тип </span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">string</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\"> не может быть назначен для типа </span><span style=\"color: #A31515\">\"number\"</span><span style=\"color: #000000\">.</span>\n\n<span style=\"color: #000000\">1 var x: number = </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">      ~</span></code></div></pre>\n<p>And help in Japanese:</p>\n<pre class=\"shiki\"><div class=\"language-id\">sh</div><div class='code-container'><code><span style=\"color: #000000\">PS C:\\ts&gt; tsc --v</span>\n<span style=\"color: #000000\">Version 2.6.0-dev.20171003</span>\n\n<span style=\"color: #000000\">PS C:\\ts&gt; tsc --locale ja-jp</span>\n<span style=\"color: #000000\">バージョン 2.6.0-dev.20171003</span>\n<span style=\"color: #000000\">構文: tsc [オプション] [ファイル ...]</span>\n\n<span style=\"color: #000000\">例:  tsc hello.ts</span>\n<span style=\"color: #000000\">    tsc --outFile file.js file.ts</span>\n<span style=\"color: #000000\">    tsc @args.txt</span>\n\n<span style=\"color: #000000\">オプション:</span>\n<span style=\"color: #000000\"> -h, --help                                 このメッセージを表示します。</span>\n<span style=\"color: #000000\"> --all                                      コンパイラ オプションをすべて表示します。</span>\n<span style=\"color: #000000\"> -v, --version                              コンパイラのバージョンを表示します。</span>\n<span style=\"color: #000000\"> --init                                     TypeScript プロジェクトを初期化して、tsconfig.json ファイルを作成します。</span>\n<span style=\"color: #000000\"> -p ファイルまたはディレクトリ, --project ファイルまたはディレクトリ  構成ファイルか、</span><span style=\"color: #A31515\">'tsconfig.json'</span><span style=\"color: #000000\"> を含むフォルダーにパスが指定されたプロジェクトをコ</span>\n<span style=\"color: #000000\">ンパイルします。</span>\n<span style=\"color: #000000\"> --pretty                                   色とコンテキストを使用してエラーとメッセージにスタイルを適用します (試験的)。</span>\n<span style=\"color: #000000\"> -w, --watch                                入力ファイルを監視します。</span>\n<span style=\"color: #000000\"> -t バージョン, --target バージョン                   ECMAScript のターゲット バージョンを指定します: </span><span style=\"color: #A31515\">'ES3'</span><span style=\"color: #000000\"> (既定)、</span><span style=\"color: #A31515\">'ES5'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'ES2015'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'ES2016'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'ES2017'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'ES</span>\n<span style=\"color: #A31515\">NEXT'</span><span style=\"color: #000000\">。</span>\n<span style=\"color: #000000\"> -m 種類, --module 種類                         モジュール コード生成を指定します: </span><span style=\"color: #A31515\">'none'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'commonjs'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'amd'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'system'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'umd'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'es2015'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'ESNext'</span><span style=\"color: #000000\">。</span>\n<span style=\"color: #000000\"> --lib                                      コンパイルに含めるライブラリ ファイルを指定します:</span>\n<span style=\"color: #000000\">                                              </span><span style=\"color: #A31515\">'es5'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es6'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es7'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2016'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2017'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'esnext'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'dom'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'dom.iterable'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'webworker'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'scripthost'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es201</span>\n<span style=\"color: #A31515\">5.core'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.collection'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.generator'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.iterable'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.promise'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.proxy'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.reflect'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.symbol'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2015.symbol.wellkno</span>\n<span style=\"color: #A31515\">wn'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2016.array.include'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2017.object'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2017.sharedmemory'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2017.string'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'es2017.intl'</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'esnext.asynciterable'</span>\n<span style=\"color: #000000\"> --allowJs                                  javascript ファイルのコンパイルを許可します。</span>\n<span style=\"color: #000000\"> --jsx 種類                                   JSX コード生成を指定します: </span><span style=\"color: #A31515\">'preserve'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'react-native'</span><span style=\"color: #000000\">、</span><span style=\"color: #A31515\">'react'</span><span style=\"color: #000000\">。</span>\n<span style=\"color: #000000\"> -d, --declaration                          対応する </span><span style=\"color: #A31515\">'.d.ts'</span><span style=\"color: #000000\"> ファイルを生成します。</span>\n<span style=\"color: #000000\"> --sourceMap                                対応する </span><span style=\"color: #A31515\">'.map'</span><span style=\"color: #000000\"> ファイルを生成します。</span>\n<span style=\"color: #000000\"> --outFile ファイル                             出力を連結して 1 つのファイルを生成します。</span>\n<span style=\"color: #000000\"> --outDir ディレクトリ                            ディレクトリへ出力構造をリダイレクトします。</span>\n<span style=\"color: #000000\"> --removeComments                           コメントを出力しないでください。</span>\n<span style=\"color: #000000\"> --noEmit                                   出力しないでください。</span>\n<span style=\"color: #000000\"> --strict                                   strict 型チェックのオプションをすべて有効にします。</span>\n<span style=\"color: #000000\"> --noImplicitAny                            暗黙的な </span><span style=\"color: #A31515\">'any'</span><span style=\"color: #000000\"> 型を含む式と宣言に関するエラーを発生させます。</span>\n<span style=\"color: #000000\"> --strictNullChecks                         厳格な null チェックを有効にします。</span>\n<span style=\"color: #000000\"> --noImplicitThis                           暗黙的な </span><span style=\"color: #A31515\">'any'</span><span style=\"color: #000000\"> 型を持つ </span><span style=\"color: #A31515\">'this'</span><span style=\"color: #000000\"> 式でエラーが発生します。</span>\n<span style=\"color: #000000\"> --alwaysStrict                             厳格モードで解析してソース ファイルごとに </span><span style=\"color: #A31515\">\"use strict\"</span><span style=\"color: #000000\"> を生成します。</span>\n<span style=\"color: #000000\"> --noUnusedLocals                           使用されていないローカルに関するエラーを報告します。</span>\n<span style=\"color: #000000\"> --noUnusedParameters                       使用されていないパラメーターに関するエラーを報告します。</span>\n<span style=\"color: #000000\"> --noImplicitReturns                        関数の一部のコード パスが値を返さない場合にエラーを報告します。</span>\n<span style=\"color: #000000\"> --noFallthroughCasesInSwitch               switch ステートメントに </span><span style=\"color: #0000FF\">case</span><span style=\"color: #000000\"> のフォールスルーがある場合にエラーを報告します。</span>\n<span style=\"color: #000000\"> --types                                    コンパイルに含む型宣言ファイル。</span>\n<span style=\"color: #000000\"> @&lt;ファイル&gt;</span></code></div></pre>\n<h2 id=\"suppress-errors-in-ts-files-using--ts-ignore-comments\"><a href=\"#suppress-errors-in-ts-files-using--ts-ignore-comments\" aria-label=\"suppress errors in ts files using  ts ignore comments 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>Suppress errors in .ts files using ’// @ts-ignore’ comments</h2>\n<p>TypeScript 2.6 support suppressing errors in .js files using <code>// @ts-ignore</code> comments placed above the offending lines.</p>\n<h5 id=\"example-3\"><a href=\"#example-3\" aria-label=\"example 3 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// @ts-ignore: Unreachable code error</span>\n<span style=\"color: #000000\">    console.log(</span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>A <code>// @ts-ignore</code> comment suppresses all errors that originate on the following line.\nIt is recommended practice to have the remainder of the comment following <code>@ts-ignore</code> explain which error is being suppressed.</p>\n<p>Please note that this comment only suppresses the error reporting, and we recommend you use this comments <em>very sparingly</em>.</p>\n<h2 id=\"faster-tsc---watch\"><a href=\"#faster-tsc---watch\" aria-label=\"faster tsc   watch 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>Faster <code>tsc --watch</code></h2>\n<p>TypeScript 2.6 brings a faster <code>--watch</code> implementation.\nThe new version optimizes code generation and checking for code bases using ES modules.\nChanges detected in a module file will result in <em>only</em> regenerating the changed module, and files that depend on it, instead of the whole project.\nProjects with large number of files should reap the most benefit from this change.</p>\n<p>The new implementation also brings performance enhancements to watching in tsserver.\nThe watcher logic has been completely rewritten to respond faster to change events.</p>\n<h2 id=\"write-only-references-now-flagged-as-unused\"><a href=\"#write-only-references-now-flagged-as-unused\" aria-label=\"write only references now flagged as unused 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>Write-only references now flagged as unused</h2>\n<p>TypeScript 2.6 adds revised implementation  the <code>--noUnusedLocals</code> and <code>--noUnusedParameters</code> <a href=\"https://www.typescriptlang.org/docs/handbook/compiler-options.html\">compiler options</a>.\nDeclarations are only written to but never read from are now flagged as unused.</p>\n<h5 id=\"example-4\"><a href=\"#example-4\" aria-label=\"example 4 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>Example</h5>\n<p>Bellow both <code>n</code> and <code>m</code> will be marked as unused, because their values are never <em>read</em>. Previously TypeScript would only check whether their values were <em>referenced</em>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> f(n: number) {</span>\n<span style=\"color: #000000\">    n = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">private</span><span style=\"color: #000000\"> m: number;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.m = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Also functions that are only called within their own bodies are considered unused.</p>\n<h5 id=\"example-5\"><a href=\"#example-5\" aria-label=\"example 5 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> f() {</span>\n<span style=\"color: #000000\">    f(); </span><span style=\"color: #008000\">// Error: 'f' is declared but its value is never read</span>\n<span style=\"color: #000000\">}</span></code></div></pre>","headings":[{"value":"Strict function types","depth":2},{"value":"Example","depth":5},{"value":"Note","depth":5},{"value":"Cache tagged template objects in modules","depth":2},{"value":"Example","depth":5},{"value":"Localized diagnostics on the command line","depth":2},{"value":"Example","depth":5},{"value":"Suppress errors in .ts files using ’// @ts-ignore’ comments","depth":2},{"value":"Example","depth":5},{"value":"Faster tsc --watch","depth":2},{"value":"Write-only references now flagged as unused","depth":2},{"value":"Example","depth":5},{"value":"Example","depth":5}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-2-6.html","title":"TypeScript 2.6"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-2-6.html","isOldHandbook":true}}}