{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-1-4.html","result":{"data":{"allSitePage":{"nodes":[{"path":"/dev-404-page/"},{"path":"/docs/handbook/advanced-types.html"},{"path":"/docs/handbook/basic-types.html"},{"path":"/docs/handbook/classes.html"},{"path":"/docs/handbook/compiler-options-in-msbuild.html"},{"path":"/docs/handbook/compiler-options.html"},{"path":"/docs/handbook/configuring-watch.html"},{"path":"/docs/handbook/declaration-merging.html"},{"path":"/docs/handbook/decorators.html"},{"path":"/docs/handbook/enums.html"},{"path":"/docs/handbook/functions.html"},{"path":"/docs/handbook/generics.html"},{"path":"/docs/handbook/integrating-with-build-tools.html"},{"path":"/docs/handbook/interfaces.html"},{"path":"/docs/handbook/iterators-and-generators.html"},{"path":"/docs/handbook/jsdoc-supported-types.html"},{"path":"/docs/handbook/jsx.html"},{"path":"/docs/handbook/literal-types.html"},{"path":"/docs/handbook/mixins.html"},{"path":"/docs/handbook/module-resolution.html"},{"path":"/docs/handbook/modules.html"},{"path":"/docs/handbook/namespaces-and-modules.html"},{"path":"/docs/handbook/namespaces.html"},{"path":"/docs/handbook/nightly-builds.html"},{"path":"/docs/handbook/project-references.html"},{"path":"/docs/handbook/symbols.html"},{"path":"/docs/handbook/"},{"path":"/docs/handbook/triple-slash-directives.html"},{"path":"/docs/handbook/type-checking-javascript-files.html"},{"path":"/docs/handbook/type-compatibility.html"},{"path":"/docs/handbook/type-inference.html"},{"path":"/docs/handbook/unions-and-intersections.html"},{"path":"/docs/handbook/utility-types.html"},{"path":"/docs/handbook/variable-declarations.html"},{"path":"/docs/handbook/writing-declaration-files.html"},{"path":"/docs/handbook/declaration-files/by-example.html"},{"path":"/docs/handbook/declaration-files/consumption.html"},{"path":"/docs/handbook/declaration-files/deep-dive.html"},{"path":"/docs/handbook/declaration-files/do-s-and-don-ts.html"},{"path":"/docs/handbook/declaration-files/introduction.html"},{"path":"/docs/handbook/declaration-files/library-structures.html"},{"path":"/docs/handbook/declaration-files/publishing.html"},{"path":"/docs/handbook/declaration-files/templates.html"},{"path":"/docs/handbook/release-notes/typescript-1-1.html"},{"path":"/docs/handbook/release-notes/typescript-1-3.html"},{"path":"/docs/handbook/release-notes/typescript-1-4.html"},{"path":"/docs/handbook/release-notes/typescript-1-5.html"},{"path":"/docs/handbook/release-notes/typescript-1-6.html"},{"path":"/docs/handbook/release-notes/typescript-1-7.html"},{"path":"/docs/handbook/release-notes/typescript-1-8.html"},{"path":"/docs/handbook/release-notes/typescript-2-0.html"},{"path":"/docs/handbook/release-notes/typescript-2-2.html"},{"path":"/docs/handbook/release-notes/typescript-2-1.html"},{"path":"/docs/handbook/release-notes/typescript-2-3.html"},{"path":"/docs/handbook/release-notes/typescript-2-4.html"},{"path":"/docs/handbook/release-notes/typescript-2-5.html"},{"path":"/docs/handbook/release-notes/typescript-2-6.html"},{"path":"/docs/handbook/release-notes/typescript-2-7.html"},{"path":"/docs/handbook/release-notes/typescript-2-8.html"},{"path":"/docs/handbook/release-notes/typescript-2-9.html"},{"path":"/docs/handbook/release-notes/typescript-3-0.html"},{"path":"/docs/handbook/release-notes/typescript-3-1.html"},{"path":"/docs/handbook/release-notes/typescript-3-2.html"},{"path":"/docs/handbook/release-notes/typescript-3-3.html"},{"path":"/docs/handbook/release-notes/typescript-3-4.html"},{"path":"/docs/handbook/release-notes/typescript-3-5.html"},{"path":"/docs/handbook/release-notes/typescript-3-6.html"},{"path":"/docs/handbook/release-notes/typescript-3-7.html"},{"path":"/docs/handbook/release-notes/typescript-3-8.html"},{"path":"/docs/handbook/asp-net-core.html"},{"path":"/docs/handbook/angular.html"},{"path":"/docs/handbook/dom-manipulation.html"},{"path":"/docs/handbook/gulp.html"},{"path":"/docs/handbook/migrating-from-javascript.html"},{"path":"/docs/handbook/react-&-webpack.html"},{"path":"/docs/handbook/react.html"},{"path":"/docs/handbook/typescript-in-5-minutes-func.html"},{"path":"/docs/handbook/typescript-in-5-minutes.html"},{"path":"/docs/handbook/typescript-in-5-minutes-oop.html"},{"path":"/docs/handbook/typescript-from-scratch.html"},{"path":"/docs/handbook/typescript-tooling-in-5-minutes.html"},{"path":"/docs/handbook/tsconfig-json.html"},{"path":"/docs/handbook/declaration-files/templates/global-modifying-module-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/global-plugin-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/global-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-class-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-function-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-plugin-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-d-ts.html"},{"path":"/docs/handbook/release-notes/overview.html"},{"path":"/tsconfig"},{"path":"/en/tsconfig"},{"path":"/ja/tsconfig"},{"path":"/vo/tsconfig"},{"path":"/play"},{"path":"/en/play"},{"path":"/es/play"},{"path":"/vo/play"},{"path":"/zh/play"},{"path":"/ja/play"},{"path":"/play/3-7/fixits/big-number-literals.ts"},{"path":"/play/3-7/fixits/const-to-let.ts"},{"path":"/play/3-7/fixits/infer-from-usage-changes.ts"},{"path":"/play/3-7/syntax-and-messaging/flattened-error-reporting.ts"},{"path":"/play/3-7/syntax-and-messaging/nullish-coalescing.ts"},{"path":"/play/3-7/syntax-and-messaging/optional-chaining.ts"},{"path":"/play/3-7/types-and-code-flow/assertion-functions.ts"},{"path":"/play/3-7/types-and-code-flow/recursive-type-references.ts"},{"path":"/play/3-7/types-and-code-flow/uncalled-function-checks.ts"},{"path":"/play/3-8/breaking-changes/checking-unions-with-index-signatures.ts"},{"path":"/play/3-8/jsdoc-improvements/accessibility-modifiers.js"},{"path":"/play/3-8/syntax-and-messaging/export-modules-from.ts"},{"path":"/play/3-8/syntax-and-messaging/private-class-fields.ts"},{"path":"/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/play/javascript/external-apis/typescript-with-node.js"},{"path":"/play/javascript/external-apis/typescript-with-web.js"},{"path":"/play/javascript/external-apis/typescript-with-webgl.js"},{"path":"/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/play/javascript/functions-with-javascript/typing-functions.ts"},{"path":"/play/javascript/helping-with-javascript/errors.ts"},{"path":"/play/javascript/helping-with-javascript/quick-fixes.ts"},{"path":"/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/play/javascript/javascript-essentials/functions.ts"},{"path":"/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/play/javascript/modern-javascript/async-await.ts"},{"path":"/play/javascript/modern-javascript/immutability.ts"},{"path":"/play/javascript/modern-javascript/import-export.ts"},{"path":"/play/javascript/modern-javascript/jsdoc-support.js"},{"path":"/play/javascript/working-with-classes/classes-101.ts"},{"path":"/play/javascript/working-with-classes/generic-classes.ts"},{"path":"/play/javascript/working-with-classes/mixins.ts"},{"path":"/play/javascript/working-with-classes/this.ts"},{"path":"/play/playground/config/javascript-playgrounds.js"},{"path":"/play/playground/config/new-compiler-defaults.ts"},{"path":"/play/playground/language/automatic-type-acquisition.ts"},{"path":"/play/playground/language/fixits.ts"},{"path":"/play/playground/tooling/mobile-support.ts"},{"path":"/play/playground/tooling/sharable-urls.ts"},{"path":"/play/playground/tooling/typescript-versions.ts"},{"path":"/play/typescript/language/soundness.ts"},{"path":"/play/typescript/language/structural-typing.ts"},{"path":"/play/typescript/language/type-guards.ts"},{"path":"/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/play/typescript/language-extensions/enums.ts"},{"path":"/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/play/typescript/meta-types/conditional-types.ts"},{"path":"/play/typescript/meta-types/discriminate-types.ts"},{"path":"/play/typescript/meta-types/indexed-types.ts"},{"path":"/play/typescript/meta-types/mapped-types.ts"},{"path":"/play/typescript/primitives/any.ts"},{"path":"/play/typescript/primitives/literals.ts"},{"path":"/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/play/typescript/primitives/unknown-and-never.ts"},{"path":"/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/play/typescript/type-primitives/nullable-types.ts"},{"path":"/play/typescript/type-primitives/tuples.ts"},{"path":"/es/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/es/play/javascript/external-apis/typescript-with-node.js"},{"path":"/es/play/javascript/external-apis/typescript-with-web.js"},{"path":"/es/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/es/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/es/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/es/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/es/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/es/play/typescript/type-primitives/nullable-types.ts"},{"path":"/es/play/typescript/type-primitives/tuples.ts"},{"path":"/ja/play/typescript/language-extensions/enums.ts"},{"path":"/ja/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/ja/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/ja/play/typescript/primitives/any.ts"},{"path":"/ja/play/typescript/primitives/literals.ts"},{"path":"/ja/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/ja/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/vo/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/vo/play/javascript/javascript-essentials/functions.ts"},{"path":"/vo/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/vo/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/zh/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/zh/play/javascript/external-apis/typescript-with-node.js"},{"path":"/zh/play/javascript/external-apis/typescript-with-web.js"},{"path":"/zh/play/javascript/external-apis/typescript-with-webgl.js"},{"path":"/zh/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/zh/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/zh/play/javascript/functions-with-javascript/typing-functions.ts"},{"path":"/zh/play/javascript/helping-with-javascript/errors.ts"},{"path":"/zh/play/javascript/helping-with-javascript/quick-fixes.ts"},{"path":"/zh/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/zh/play/javascript/javascript-essentials/functions.ts"},{"path":"/zh/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/zh/play/javascript/modern-javascript/import-export.ts"},{"path":"/zh/play/javascript/modern-javascript/jsdoc-support.js"},{"path":"/zh/play/javascript/working-with-classes/classes-101.ts"},{"path":"/zh/play/javascript/working-with-classes/generic-classes.ts"},{"path":"/zh/play/javascript/working-with-classes/mixins.ts"},{"path":"/zh/play/javascript/working-with-classes/this.ts"},{"path":"/zh/play/playground/config/javascript-playgrounds.js"},{"path":"/zh/play/playground/config/new-compiler-defaults.ts"},{"path":"/zh/play/playground/language/automatic-type-acquisition.ts"},{"path":"/zh/play/playground/language/fixits.ts"},{"path":"/zh/play/playground/tooling/mobile-support.ts"},{"path":"/zh/play/playground/tooling/sharable-urls.ts"},{"path":"/zh/play/playground/tooling/typescript-versions.ts"},{"path":"/zh/play/typescript/language/soundness.ts"},{"path":"/zh/play/typescript/language/structural-typing.ts"},{"path":"/zh/play/typescript/language/type-guards.ts"},{"path":"/zh/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/zh/play/typescript/language-extensions/enums.ts"},{"path":"/zh/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/zh/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/zh/play/typescript/meta-types/conditional-types.ts"},{"path":"/zh/play/typescript/meta-types/discriminate-types.ts"},{"path":"/zh/play/typescript/meta-types/indexed-types.ts"},{"path":"/zh/play/typescript/meta-types/mapped-types.ts"},{"path":"/zh/play/typescript/primitives/any.ts"},{"path":"/zh/play/typescript/primitives/literals.ts"},{"path":"/zh/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/zh/play/typescript/primitives/unknown-and-never.ts"},{"path":"/zh/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/zh/play/typescript/type-primitives/nullable-types.ts"},{"path":"/zh/play/typescript/type-primitives/tuples.ts"},{"path":"/zh/play/javascript/modern-javascript/immutability.ts"},{"path":"/zh/play/javascript/modern-javascript/async-await.ts"},{"path":"/zh/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/community"},{"path":"/es/community"},{"path":"/ja/community"},{"path":"/vo/community"},{"path":"/zh/community"},{"path":"/download"},{"path":"/es/download"},{"path":"/ja/download"},{"path":"/vo/download"},{"path":"/zh/download"},{"path":"/empty"},{"path":"/es/empty"},{"path":"/ja/empty"},{"path":"/vo/empty"},{"path":"/zh/empty"},{"path":"/"},{"path":"/es/"},{"path":"/ja/"},{"path":"/vo/"},{"path":"/zh/"},{"path":"/tools"},{"path":"/es/tools"},{"path":"/ja/tools"},{"path":"/vo/tools"},{"path":"/zh/tools"},{"path":"/why-create-typescript"},{"path":"/es/why-create-typescript"},{"path":"/ja/why-create-typescript"},{"path":"/vo/why-create-typescript"},{"path":"/zh/why-create-typescript"},{"path":"/docs/home"},{"path":"/es/docs/home"},{"path":"/ja/docs/home"},{"path":"/vo/docs/home"},{"path":"/zh/docs/home"},{"path":"/dev/playground-plugins/"},{"path":"/dev/sandbox/"},{"path":"/dev/twoslash/"},{"path":"/dev/typescript-vfs/"}]},"markdownRemark":{"id":"a3260d58-f3fc-56f5-8a91-32eb13221231","excerpt":"Union types Overview Union types are a powerful way to express a value that can be one of several types. For example, you might have an API for running a…","html":"<h2 id=\"union-types\" style=\"position:relative;\"><a href=\"#union-types\" aria-label=\"union types permalink\" class=\"anchor before\"><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>Union types</h2>\n<h3 id=\"overview\" style=\"position:relative;\"><a href=\"#overview\" aria-label=\"overview permalink\" class=\"anchor before\"><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>Overview</h3>\n<p>Union types are a powerful way to express a value that can be one of several types. For example, you might have an API for running a program that takes a commandline as either a <code>string</code>, a <code>string[]</code> or a function that returns a <code>string</code>. You can now write:</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\"> RunOptions {</span>\n<span style=\"color: #000000\">   program: string;</span>\n<span style=\"color: #000000\">   commandline: string[]|string|(() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> string);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Assignment to union types works very intuitively — anything you could assign to one of the union type’s members is assignable to the union:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> opts: RunOptions = </span><span style=\"color: #008000\">/* ... */</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">opts.commandline = </span><span style=\"color: #A31515\">'-hello world'</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">opts.commandline = [</span><span style=\"color: #A31515\">'-hello'</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\">opts.commandline = [</span><span style=\"color: #09835A\">42</span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// Error, number is not string or string[]</span></code></div></pre>\n<p>When reading from a union type, you can see any properties that are shared by them:</p>\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\"> (opts.length === </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">) { </span><span style=\"color: #008000\">// OK, string and string[] both have 'length' property</span>\n<span style=\"color: #000000\">  console.log(</span><span style=\"color: #A31515\">\"it's empty\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Using Type Guards, you can easily work with a variable of a union type:</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\"> formatCommandline(c: string|string[]) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">typeof</span><span style=\"color: #000000\"> c === </span><span style=\"color: #A31515\">'string'</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> c.trim();</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">else</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> c.join(</span><span style=\"color: #A31515\">' '</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h3 id=\"stricter-generics\" style=\"position:relative;\"><a href=\"#stricter-generics\" aria-label=\"stricter generics permalink\" class=\"anchor before\"><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>Stricter Generics</h3>\n<p>With union types able to represent a wide range of type scenarios, we’ve decided to improve the strictness of certain generic calls. Previously, code like this would (surprisingly) compile without error:</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\"> equal&lt;T&gt;(lhs: T, rhs: T): boolean {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> lhs === rhs;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Previously: No error</span>\n<span style=\"color: #008000\">// New behavior: Error, no best common type between 'string' and 'number'</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> e = equal(</span><span style=\"color: #09835A\">42</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p>With union types, you can now specify the desired behavior at both the function declaration site and the call site:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// 'choose' function where types must match</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> choose1&lt;T&gt;(a: T, b: T): T { </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> Math.random() &gt; </span><span style=\"color: #09835A\">0.5</span><span style=\"color: #000000\"> ? a : b }</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> a = choose1(</span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">42</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> b = choose1&lt;string|number&gt;(</span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">42</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK</span>\n\n<span style=\"color: #008000\">// 'choose' function where types need not match</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> choose2&lt;T, U&gt;(a: T, b: U): T|U { </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> Math.random() &gt; </span><span style=\"color: #09835A\">0.5</span><span style=\"color: #000000\"> ? a : b }</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> c = choose2(</span><span style=\"color: #A31515\">'bar'</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">'foo'</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK, c: string</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> d = choose2(</span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">42</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK, d: string|number</span></code></div></pre>\n<h3 id=\"better-type-inference\" style=\"position:relative;\"><a href=\"#better-type-inference\" aria-label=\"better type inference permalink\" class=\"anchor before\"><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>Better Type Inference</h3>\n<p>Union types also allow for better type inference in arrays and other places where you might have multiple kinds of values in a collection:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x = [</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// x: Array&lt;string|number&gt;</span>\n<span style=\"color: #000000\">x[</span><span style=\"color: #09835A\">0</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\">x[</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">] = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error, boolean is not string or number</span></code></div></pre>\n<h2 id=\"let-declarations\" style=\"position:relative;\"><a href=\"#let-declarations\" aria-label=\"let declarations permalink\" class=\"anchor before\"><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><code>let</code> declarations</h2>\n<p>In JavaScript, <code>var</code> declarations are “hoisted” to the top of their enclosing scope. This can result in confusing bugs:</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: #008000\">// meant to write 'y' here</span>\n<span style=\"color: #008000\">/* later in the same block */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x = </span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>The new ES6 keyword <code>let</code>, now supported in TypeScript, declares a variable with more intuitive “block” semantics. A <code>let</code> variable can only be referred to after its declaration, and is scoped to the syntactic block where it is defined:</p>\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\"> (foo) {</span>\n<span style=\"color: #000000\">    console.log(x); </span><span style=\"color: #008000\">// Error, cannot refer to x before its declaration</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x = </span><span style=\"color: #A31515\">'hello'</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">else</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    console.log(x); </span><span style=\"color: #008000\">// Error, x is not declared in this block</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><code>let</code> is only available when targeting ECMAScript 6 (<code>--target ES6</code>).</p>\n<h2 id=\"const-declarations\" style=\"position:relative;\"><a href=\"#const-declarations\" aria-label=\"const declarations permalink\" class=\"anchor before\"><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><code>const</code> declarations</h2>\n<p>The other new ES6 declaration type supported in TypeScript is <code>const</code>. A <code>const</code> variable may not be assigned to, and must be initialized where it is declared. This is useful for declarations where you don’t want to change the value after its initialization:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> halfPi = Math.PI / </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">halfPi = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error, can't assign to a `const`</span></code></div></pre>\n<p><code>const</code> is only available when targeting ECMAScript 6 (<code>--target ES6</code>).</p>\n<h2 id=\"template-strings\" style=\"position:relative;\"><a href=\"#template-strings\" aria-label=\"template strings permalink\" class=\"anchor before\"><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>Template strings</h2>\n<p>TypeScript now supports ES6 template strings. These are an easy way to embed arbitrary expressions in strings:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> name = </span><span style=\"color: #A31515\">\"TypeScript\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> greeting  = </span><span style=\"color: #A31515\">`Hello, </span><span style=\"color: #0000FF\">${</span><span style=\"color: #A31515\">name</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\">! Your name has </span><span style=\"color: #0000FF\">${</span><span style=\"color: #A31515\">name.length</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\"> characters`</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>When compiling to pre-ES6 targets, the string is decomposed:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> name = </span><span style=\"color: #A31515\">\"TypeScript!\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> greeting = </span><span style=\"color: #A31515\">\"Hello, \"</span><span style=\"color: #000000\"> + name + </span><span style=\"color: #A31515\">\"! Your name has \"</span><span style=\"color: #000000\"> + name.length + </span><span style=\"color: #A31515\">\" characters\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h2 id=\"type-guards\" style=\"position:relative;\"><a href=\"#type-guards\" aria-label=\"type guards permalink\" class=\"anchor before\"><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>Type Guards</h2>\n<p>A common pattern in JavaScript is to use <code>typeof</code> or <code>instanceof</code> to examine the type of an expression at runtime. TypeScript now understands these conditions and will change type inference accordingly when used in an <code>if</code> block.</p>\n<p>Using <code>typeof</code> to test a variable:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x: any = </span><span style=\"color: #008000\">/* ... */</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">if</span><span style=\"color: #000000\">(</span><span style=\"color: #0000FF\">typeof</span><span style=\"color: #000000\"> x === </span><span style=\"color: #A31515\">'string'</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    console.log(x.subtr(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">)); </span><span style=\"color: #008000\">// Error, 'subtr' does not exist on 'string'</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #008000\">// x is still any here</span>\n<span style=\"color: #000000\">x.unknown(); </span><span style=\"color: #008000\">// OK</span></code></div></pre>\n<p>Using <code>typeof</code> with union types and <code>else</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x: string | HTMLElement = </span><span style=\"color: #008000\">/* ... */</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">if</span><span style=\"color: #000000\">(</span><span style=\"color: #0000FF\">typeof</span><span style=\"color: #000000\"> x === </span><span style=\"color: #A31515\">'string'</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// x is string here, as shown above</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">else</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// x is HTMLElement here</span>\n<span style=\"color: #000000\">    console.log(x.innerHTML);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Using <code>instanceof</code> with classes and union types:</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\"> Dog { woof() { } }</span>\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Cat { meow() { } }</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> pet: Dog|Cat = </span><span style=\"color: #008000\">/* ... */</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (pet </span><span style=\"color: #0000FF\">instanceof</span><span style=\"color: #000000\"> Dog) {</span>\n<span style=\"color: #000000\">    pet.woof(); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">else</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    pet.woof(); </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"type-aliases\" style=\"position:relative;\"><a href=\"#type-aliases\" aria-label=\"type aliases permalink\" class=\"anchor before\"><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>Type Aliases</h2>\n<p>You can now define an <em>alias</em> for a type using the <code>type</code> keyword:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> PrimitiveArray = Array&lt;string|number|boolean&gt;;</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> MyNumber = number;</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> NgScope = ng.IScope;</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Callback = () </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void;</span></code></div></pre>\n<p>Type aliases are exactly the same as their original types; they are simply alternative names.</p>\n<h2 id=\"const-enum-completely-inlined-enums\" style=\"position:relative;\"><a href=\"#const-enum-completely-inlined-enums\" aria-label=\"const enum completely inlined enums permalink\" class=\"anchor before\"><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><code>const enum</code> (completely inlined enums)</h2>\n<p>Enums are very useful, but some programs don’t actually need the generated code and would benefit from simply inlining all instances of enum members with their numeric equivalents. The new <code>const enum</code> declaration works just like a regular <code>enum</code> for type safety, but erases completely at compile time.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> Suit { Clubs, Diamonds, Hearts, Spades }</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> d = Suit.Diamonds;</span></code></div></pre>\n<p>Compiles to exactly:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> d = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>TypeScript will also now compute enum values when possible:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> MyFlags {</span>\n<span style=\"color: #000000\">  None = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  Neat = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  Cool = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  Awesome = </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  Best = Neat | Cool | Awesome</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> b = MyFlags.Best; </span><span style=\"color: #008000\">// emits var b = 7;</span></code></div></pre>\n<h2 id=\"-noemitonerror-commandline-option\" style=\"position:relative;\"><a href=\"#-noemitonerror-commandline-option\" aria-label=\" noemitonerror commandline option permalink\" class=\"anchor before\"><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><code>-noEmitOnError</code> commandline option</h2>\n<p>The default behavior for the TypeScript compiler is to still emit .js files if there were type errors (for example, an attempt to assign a <code>string</code> to a <code>number</code>). This can be undesirable on build servers or other scenarios where only output from a “clean” build is desired. The new flag <code>noEmitOnError</code> prevents the compiler from emitting .js code if there were any errors.</p>\n<p>This is now the default for MSBuild projects; this allows MSBuild incremental build to work as expected, as outputs are only generated on clean builds.</p>\n<h2 id=\"amd-module-names\" style=\"position:relative;\"><a href=\"#amd-module-names\" aria-label=\"amd module names permalink\" class=\"anchor before\"><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>AMD Module names</h2>\n<p>By default AMD modules are generated anonymous. This can lead to problems when other tools are used to process the resulting modules like a bundlers (e.g. <code>r.js</code>).</p>\n<p>The new <code>amd-module name</code> tag allows passing an optional module name to the compiler:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">//// [amdModule.ts]</span>\n<span style=\"color: #008000\">///</span><span style=\"color: #800000\">&lt;amd-module</span><span style=\"color: #008000\"> </span><span style=\"color: #DC0000\">name</span><span style=\"color: #000000\">=</span><span style=\"color: #A31515\">'NamedModule'</span><span style=\"color: #800000\">/&gt;</span>\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Will result in assigning the name <code>NamedModule</code> to the module as part of calling the AMD <code>define</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">//// [amdModule.js]</span>\n<span style=\"color: #000000\">define(</span><span style=\"color: #A31515\">\"NamedModule\"</span><span style=\"color: #000000\">, [</span><span style=\"color: #A31515\">\"require\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"exports\"</span><span style=\"color: #000000\">], </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> (require, exports) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> C = (</span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> C() {</span>\n<span style=\"color: #000000\">        }</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> C;</span>\n<span style=\"color: #000000\">    })();</span>\n<span style=\"color: #000000\">    exports.C = C;</span>\n<span style=\"color: #000000\">});</span></code></div></pre>","headings":[{"value":"Union types","depth":2},{"value":"Overview","depth":3},{"value":"Stricter Generics","depth":3},{"value":"Better Type Inference","depth":3},{"value":"let declarations","depth":2},{"value":"const declarations","depth":2},{"value":"Template strings","depth":2},{"value":"Type Guards","depth":2},{"value":"Type Aliases","depth":2},{"value":"const enum (completely inlined enums)","depth":2},{"value":"-noEmitOnError commandline option","depth":2},{"value":"AMD Module names","depth":2}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-1-4.html","title":"TypeScript 1.4"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-1-4.html","isOldHandbook":true}}}