{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-2-0.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":"3d33916c-6ec1-5423-be08-4d35a1c309f7","excerpt":"Null- and undefined-aware types TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively.\nPreviously it was…","html":"<h2 id=\"null--and-undefined-aware-types\" style=\"position:relative;\"><a href=\"#null--and-undefined-aware-types\" aria-label=\"null  and undefined aware 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>Null- and undefined-aware types</h2>\n<p>TypeScript has two special types, Null and Undefined, that have the values <code>null</code> and <code>undefined</code> respectively.\nPreviously it was not possible to explicitly name these types, but <code>null</code> and <code>undefined</code> may now be used as type names regardless of type checking mode.</p>\n<p>The type checker previously considered <code>null</code> and <code>undefined</code> assignable to anything.\nEffectively, <code>null</code> and <code>undefined</code> were valid values of <em>every</em> type and it wasn’t possible to specifically exclude them (and therefore not possible to detect erroneous use of them).</p>\n<h2 id=\"--strictnullchecks\" style=\"position:relative;\"><a href=\"#--strictnullchecks\" aria-label=\"  strictnullchecks 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>--strictNullChecks</code></h2>\n<p><code>--strictNullChecks</code> switches to a new strict null checking mode.</p>\n<p>In strict null checking mode, the <code>null</code> and <code>undefined</code> values are <em>not</em> in the domain of every type and are only assignable to themselves and <code>any</code> (the one exception being that <code>undefined</code> is also assignable to <code>void</code>).\nSo, whereas <code>T</code> and <code>T | undefined</code> are considered synonymous in regular type checking mode (because <code>undefined</code> is considered a subtype of any <code>T</code>), they are different types in strict type checking mode, and only <code>T | undefined</code> permits <code>undefined</code> values. The same is true for the relationship of <code>T</code> to <code>T | null</code>.</p>\n<h5 id=\"example\" style=\"position:relative;\"><a href=\"#example\" aria-label=\"example 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x: number;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> y: number | undefined;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> z: number | null | undefined;</span>\n<span style=\"color: #000000\">x = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">y = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">z = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">x = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">y = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">z = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">x = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">y = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">z = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">x = y;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">x = z;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">y = x;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">y = z;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #000000\">z = x;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">z = y;  </span><span style=\"color: #008000\">// Ok</span></code></div></pre>\n<h2 id=\"assigned-before-use-checking\" style=\"position:relative;\"><a href=\"#assigned-before-use-checking\" aria-label=\"assigned before use checking 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>Assigned-before-use checking</h2>\n<p>In strict null checking mode the compiler requires every reference to a local variable of a type that doesn’t include <code>undefined</code> to be preceded by an assignment to that variable in every possible preceding code path.</p>\n<h5 id=\"example-1\" style=\"position:relative;\"><a href=\"#example-1\" aria-label=\"example 1 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x: number;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> y: number | null;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> z: number | undefined;</span>\n<span style=\"color: #000000\">x;  </span><span style=\"color: #008000\">// Error, reference not preceded by assignment</span>\n<span style=\"color: #000000\">y;  </span><span style=\"color: #008000\">// Error, reference not preceded by assignment</span>\n<span style=\"color: #000000\">z;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">x = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">y = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">x;  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">y;  </span><span style=\"color: #008000\">// Ok</span></code></div></pre>\n<p>The compiler checks that variables are definitely assigned by performing <em>control flow based type analysis</em>. See later for further details on this topic.</p>\n<h2 id=\"optional-parameters-and-properties\" style=\"position:relative;\"><a href=\"#optional-parameters-and-properties\" aria-label=\"optional parameters and properties 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>Optional parameters and properties</h2>\n<p>Optional parameters and properties automatically have <code>undefined</code> added to their types, even when their type annotations don’t specifically include <code>undefined</code>.\nFor example, the following two types are identical:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T1 = (x?: number) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> string;              </span><span style=\"color: #008000\">// x has type number | undefined</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T2 = (x?: number | undefined) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> string;  </span><span style=\"color: #008000\">// x has type number | undefined</span></code></div></pre>\n<h2 id=\"non-null-and-non-undefined-type-guards\" style=\"position:relative;\"><a href=\"#non-null-and-non-undefined-type-guards\" aria-label=\"non null and non undefined 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>Non-null and non-undefined type guards</h2>\n<p>A property access or a function call produces a compile-time error if the object or function is of a type that includes <code>null</code> or <code>undefined</code>.\nHowever, type guards are extended to support non-null and non-undefined checks.</p>\n<h5 id=\"example-2\" style=\"position:relative;\"><a href=\"#example-2\" aria-label=\"example 2 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> f(x: number): string;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x: number | null | undefined;</span>\n<span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (x) {</span>\n<span style=\"color: #000000\">    f(x);  </span><span style=\"color: #008000\">// Ok, type of x is number here</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">else</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    f(x);  </span><span style=\"color: #008000\">// Error, type of x is number? here</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> a = x != </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\"> ? f(x) : </span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type of a is string</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> b = x && f(x);  </span><span style=\"color: #008000\">// Type of b is string | 0 | null | undefined</span></code></div></pre>\n<p>Non-null and non-undefined type guards may use the <code>==</code>, <code>!=</code>, <code>===</code>, or <code>!==</code> operator to compare to <code>null</code> or <code>undefined</code>, as in <code>x != null</code> or <code>x === undefined</code>.\nThe effects on subject variable types accurately reflect JavaScript semantics (e.g. double-equals operators check for both values no matter which one is specified whereas triple-equals only checks for the specified value).</p>\n<h2 id=\"dotted-names-in-type-guards\" style=\"position:relative;\"><a href=\"#dotted-names-in-type-guards\" aria-label=\"dotted names in 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>Dotted names in type guards</h2>\n<p>Type guards previously only supported checking local variables and parameters.\nType guards now support checking “dotted names” consisting of a variable or parameter name followed one or more property accesses.</p>\n<h5 id=\"example-3\" style=\"position:relative;\"><a href=\"#example-3\" aria-label=\"example 3 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>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\"> Options {</span>\n<span style=\"color: #000000\">    location?: {</span>\n<span style=\"color: #000000\">        x?: number;</span>\n<span style=\"color: #000000\">        y?: number;</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\"> foo(options?: Options) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (options && options.location && options.location.x) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> x = options.location.x;  </span><span style=\"color: #008000\">// Type of x is number</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Type guards for dotted names also work with user defined type guard functions and the <code>typeof</code> and <code>instanceof</code> operators and do not depend on the <code>--strictNullChecks</code> compiler option.</p>\n<p>A type guard for a dotted name has no effect following an assignment to any part of the dotted name.\nFor example, a type guard for <code>x.y.z</code> will have no effect following an assignment to <code>x</code>, <code>x.y</code>, or <code>x.y.z</code>.</p>\n<h2 id=\"expression-operators\" style=\"position:relative;\"><a href=\"#expression-operators\" aria-label=\"expression operators 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>Expression operators</h2>\n<p>Expression operators permit operand types to include <code>null</code> and/or <code>undefined</code> but always produce values of non-null and non-undefined types.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> sum(a: number | null, b: number | null) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> a + b;  </span><span style=\"color: #008000\">// Produces value of type number</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>The <code>&#x26;&#x26;</code> operator adds <code>null</code> and/or <code>undefined</code> to the type of the right operand depending on which are present in the type of the left operand, and the <code>||</code> operator removes both <code>null</code> and <code>undefined</code> from the type of the left operand in the resulting union type.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Entity {</span>\n<span style=\"color: #000000\">    name: string;</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x: Entity | null;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> s = x && x.name;  </span><span style=\"color: #008000\">// s is of type string | null</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> y = x || { name: </span><span style=\"color: #A31515\">\"test\"</span><span style=\"color: #000000\"> };  </span><span style=\"color: #008000\">// y is of type Entity</span></code></div></pre>\n<h2 id=\"type-widening\" style=\"position:relative;\"><a href=\"#type-widening\" aria-label=\"type widening 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 widening</h2>\n<p>The <code>null</code> and <code>undefined</code> types are <em>not</em> widened to <code>any</code> in strict null checking mode.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> z = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type of z is null</span></code></div></pre>\n<p>In regular type checking mode the inferred type of <code>z</code> is <code>any</code> because of widening, but in strict null checking mode the inferred type of <code>z</code> is <code>null</code> (and therefore, absent a type annotation, <code>null</code> is the only possible value for <code>z</code>).</p>\n<h2 id=\"non-null-assertion-operator\" style=\"position:relative;\"><a href=\"#non-null-assertion-operator\" aria-label=\"non null assertion operator 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>Non-null assertion operator</h2>\n<p>A new <code>!</code> post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact.\nSpecifically, the operation <code>x!</code> produces a value of the type of <code>x</code> with <code>null</code> and <code>undefined</code> excluded.\nSimilar to type assertions of the forms <code>&#x3C;T>x</code> and <code>x as T</code>, the <code>!</code> non-null assertion operator is simply removed in the emitted JavaScript code.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compiled with --strictNullChecks</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> validateEntity(e?: Entity) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// Throw exception if e is null or invalid entity</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> processEntity(e?: Entity) {</span>\n<span style=\"color: #000000\">    validateEntity(e);</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> s = e!.name;  </span><span style=\"color: #008000\">// Assert that e is non-null and access name</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"compatibility\" style=\"position:relative;\"><a href=\"#compatibility\" aria-label=\"compatibility 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>Compatibility</h2>\n<p>The new features are designed such that they can be used in both strict null checking mode and regular type checking mode.\nIn particular, the <code>null</code> and <code>undefined</code> types are automatically erased from union types in regular type checking mode (because they are subtypes of all other types), and the <code>!</code> non-null assertion expression operator is permitted but has no effect in regular type checking mode. Thus, declaration files that are updated to use null- and undefined-aware types can still be used in regular type checking mode for backwards compatibility.</p>\n<p>In practical terms, strict null checking mode requires that all files in a compilation are null- and undefined-aware.</p>\n<h2 id=\"control-flow-based-type-analysis\" style=\"position:relative;\"><a href=\"#control-flow-based-type-analysis\" aria-label=\"control flow based type analysis 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>Control flow based type analysis</h2>\n<p>TypeScript 2.0 implements a control flow-based type analysis for local variables and parameters.\nPreviously, the type analysis performed for type guards was limited to <code>if</code> statements and <code>?:</code> conditional expressions and didn’t include effects of assignments and control flow constructs such as <code>return</code> and <code>break</code> statements.\nWith TypeScript 2.0, the type checker analyses all possible flows of control in statements and expressions to produce the most specific type possible (the <em>narrowed type</em>) at any given location for a local variable or parameter that is declared to have a union type.</p>\n<h5 id=\"example-4\" style=\"position:relative;\"><a href=\"#example-4\" aria-label=\"example 4 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>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\"> foo(x: string | number | boolean) {</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\"> x === </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">        x; </span><span style=\"color: #008000\">// type of x is string here</span>\n<span style=\"color: #000000\">        x = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">        x; </span><span style=\"color: #008000\">// type of x is number here</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    x; </span><span style=\"color: #008000\">// type of x is number | boolean here</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> bar(x: string | number) {</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\"> x === </span><span style=\"color: #A31515\">\"number\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    x; </span><span style=\"color: #008000\">// type of x is string here</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Control flow based type analysis is particularly relevant in <code>--strictNullChecks</code> mode because nullable types are represented using union types:</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\"> test(x: string | null) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (x === </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    x; </span><span style=\"color: #008000\">// type of x is string in remainder of function</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Furthermore, in <code>--strictNullChecks</code> mode, control flow based type analysis includes <em>definite assignment analysis</em> for local variables of types that don’t permit the value <code>undefined</code>.</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\"> mumble(check: boolean) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x: number; </span><span style=\"color: #008000\">// Type doesn't permit undefined</span>\n<span style=\"color: #000000\">    x; </span><span style=\"color: #008000\">// Error, x is undefined</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (check) {</span>\n<span style=\"color: #000000\">        x = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">        x; </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    x; </span><span style=\"color: #008000\">// Error, x is possibly undefined</span>\n<span style=\"color: #000000\">    x = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    x; </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"tagged-union-types\" style=\"position:relative;\"><a href=\"#tagged-union-types\" aria-label=\"tagged 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>Tagged union types</h2>\n<p>TypeScript 2.0 implements support for tagged (or discriminated) union types.\nSpecifically, the TS compiler now support type guards that narrow union types based on tests of a discriminant property and furthermore extend that capability to <code>switch</code> statements.</p>\n<h5 id=\"example-5\" style=\"position:relative;\"><a href=\"#example-5\" aria-label=\"example 5 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>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\"> Square {</span>\n<span style=\"color: #000000\">    kind: </span><span style=\"color: #A31515\">\"square\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    size: number;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Rectangle {</span>\n<span style=\"color: #000000\">    kind: </span><span style=\"color: #A31515\">\"rectangle\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    width: number;</span>\n<span style=\"color: #000000\">    height: number;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Circle {</span>\n<span style=\"color: #000000\">    kind: </span><span style=\"color: #A31515\">\"circle\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    radius: number;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Shape = Square | Rectangle | Circle;</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> area(s: Shape) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// In the following switch statement, the type of s is narrowed in each case clause</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// according to the value of the discriminant property, thus allowing the other properties</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// of that variant to be accessed without a type assertion.</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">switch</span><span style=\"color: #000000\"> (s.kind) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">case</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"square\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> s.size * s.size;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">case</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"rectangle\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> s.width * s.height;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">case</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"circle\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> Math.PI * s.radius * s.radius;</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\"> test1(s: Shape) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (s.kind === </span><span style=\"color: #A31515\">\"square\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">        s;  </span><span style=\"color: #008000\">// Square</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\">        s;  </span><span style=\"color: #008000\">// Rectangle | Circle</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\"> test2(s: Shape) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (s.kind === </span><span style=\"color: #A31515\">\"square\"</span><span style=\"color: #000000\"> || s.kind === </span><span style=\"color: #A31515\">\"rectangle\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    s;  </span><span style=\"color: #008000\">// Circle</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>A <em>discriminant property type guard</em> is an expression of the form <code>x.p == v</code>, <code>x.p === v</code>, <code>x.p != v</code>, or <code>x.p !== v</code>, where <code>p</code> and <code>v</code> are a property and an expression of a string literal type or a union of string literal types.\nThe discriminant property type guard narrows the type of <code>x</code> to those constituent types of <code>x</code> that have a discriminant property <code>p</code> with one of the possible values of <code>v</code>.</p>\n<p>Note that we currently only support discriminant properties of string literal types.\nWe intend to later add support for boolean and numeric literal types.</p>\n<h2 id=\"the-never-type\" style=\"position:relative;\"><a href=\"#the-never-type\" aria-label=\"the never type 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>The <code>never</code> type</h2>\n<p>TypeScript 2.0 introduces a new primitive type <code>never</code>.\nThe <code>never</code> type represents the type of values that never occur.\nSpecifically, <code>never</code> is the return type for functions that never return and <code>never</code> is the type of variables under type guards that are never true.</p>\n<p>The <code>never</code> type has the following characteristics:</p>\n<ul>\n<li><code>never</code> is a subtype of and assignable to every type.</li>\n<li>No type is a subtype of or assignable to <code>never</code> (except <code>never</code> itself).</li>\n<li>In a function expression or arrow function with no return type annotation, if the function has no <code>return</code> statements, or only <code>return</code> statements with expressions of type <code>never</code>, and if the end point of the function is not reachable (as determined by control flow analysis), the inferred return type for the function is <code>never</code>.</li>\n<li>In a function with an explicit <code>never</code> return type annotation, all <code>return</code> statements (if any) must have expressions of type <code>never</code> and the end point of the function must not be reachable.</li>\n</ul>\n<p>Because <code>never</code> is a subtype of every type, it is always omitted from union types and it is ignored in function return type inference as long as there are other types being returned.</p>\n<p>Some examples of functions returning <code>never</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Function returning never must have unreachable end point</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> error(message: string): never {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">throw</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Error(message);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Inferred return type is never</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> fail() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> error(</span><span style=\"color: #A31515\">\"Something failed\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Function returning never must have unreachable end point</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> infiniteLoop(): never {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">while</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Some examples of use of functions returning <code>never</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Inferred return type is number</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> move1(direction: </span><span style=\"color: #A31515\">\"up\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"down\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">switch</span><span style=\"color: #000000\"> (direction) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">case</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"up\"</span><span style=\"color: #000000\">:</span>\n<span style=\"color: #000000\">            </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">case</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"down\"</span><span style=\"color: #000000\">:</span>\n<span style=\"color: #000000\">            </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> -</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> error(</span><span style=\"color: #A31515\">\"Should never get here\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Inferred return type is number</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> move2(direction: </span><span style=\"color: #A31515\">\"up\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"down\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> direction === </span><span style=\"color: #A31515\">\"up\"</span><span style=\"color: #000000\"> ? </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> :</span>\n<span style=\"color: #000000\">        direction === </span><span style=\"color: #A31515\">\"down\"</span><span style=\"color: #000000\"> ? -</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> :</span>\n<span style=\"color: #000000\">        error(</span><span style=\"color: #A31515\">\"Should never get here\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Inferred return type is T</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> check&lt;T&gt;(x: T | undefined) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> x || error(</span><span style=\"color: #A31515\">\"Undefined value\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Because <code>never</code> is assignable to every type, a function returning <code>never</code> can be used when a callback returning a more specific type is required:</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\"> test(cb: () </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> string) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> s = cb();</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> s;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">test(() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">test(() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> fail());</span>\n<span style=\"color: #000000\">test(() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> { </span><span style=\"color: #0000FF\">throw</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Error(); })</span></code></div></pre>\n<h2 id=\"read-only-properties-and-index-signatures\" style=\"position:relative;\"><a href=\"#read-only-properties-and-index-signatures\" aria-label=\"read only properties and index signatures 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>Read-only properties and index signatures</h2>\n<p>A property or index signature can now be declared with the <code>readonly</code> modifier is considered read-only.</p>\n<p>Read-only properties may have initializers and may be assigned to in constructors within the same class declaration, but otherwise assignments to read-only properties are disallowed.</p>\n<p>In addition, entities are <em>implicitly</em> read-only in several situations:</p>\n<ul>\n<li>A property declared with a <code>get</code> accessor and no <code>set</code> accessor is considered read-only.</li>\n<li>In the type of an enum object, enum members are considered read-only properties.</li>\n<li>In the type of a module object, exported <code>const</code> variables are considered read-only properties.</li>\n<li>An entity declared in an <code>import</code> statement is considered read-only.</li>\n<li>An entity accessed through an ES2015 namespace import is considered read-only (e.g. <code>foo.x</code> is read-only when <code>foo</code> is declared as <code>import * as foo from \"foo\"</code>).</li>\n</ul>\n<h5 id=\"example-6\" style=\"position:relative;\"><a href=\"#example-6\" aria-label=\"example 6 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>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\"> Point {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">readonly</span><span style=\"color: #000000\"> x: number;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">readonly</span><span style=\"color: #000000\"> y: number;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> p1: Point = { x: </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">, y: </span><span style=\"color: #09835A\">20</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #000000\">p1.x = </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Error, p1.x is read-only</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> p2 = { x: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, y: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> p3: Point = p2;  </span><span style=\"color: #008000\">// Ok, read-only alias for p2</span>\n<span style=\"color: #000000\">p3.x = </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Error, p3.x is read-only</span>\n<span style=\"color: #000000\">p2.x = </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Ok, but also changes p3.x because of aliasing</span></code></div></pre>\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\"> Foo {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">readonly</span><span style=\"color: #000000\"> a = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">readonly</span><span style=\"color: #000000\"> b: string;</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\">.b = </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Assignment permitted in constructor</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> a: Array&lt;number&gt; = [</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">];</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> b: ReadonlyArray&lt;number&gt; = a;</span>\n<span style=\"color: #000000\">b[</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">] = </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">;      </span><span style=\"color: #008000\">// Error, elements are read-only</span>\n<span style=\"color: #000000\">b.push(</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">);     </span><span style=\"color: #008000\">// Error, no push method (because it mutates array)</span>\n<span style=\"color: #000000\">b.length = </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Error, length is read-only</span>\n<span style=\"color: #000000\">a = b;         </span><span style=\"color: #008000\">// Error, mutating methods are missing</span></code></div></pre>\n<h2 id=\"specifying-the-type-of-this-for-functions\" style=\"position:relative;\"><a href=\"#specifying-the-type-of-this-for-functions\" aria-label=\"specifying the type of this for functions 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>Specifying the type of <code>this</code> for functions</h2>\n<p>Following up on specifying the type of <code>this</code> in a class or an interface, functions and methods can now declare the type of <code>this</code> they expect.</p>\n<p>By default the type of <code>this</code> inside a function is <code>any</code>.\nStarting with TypeScript 2.0, you can provide an explicit <code>this</code> parameter.\n<code>this</code> parameters are fake parameters that come first in the parameter list of a function:</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(this: void) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// make sure `this` is unusable in this standalone function</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"this-parameters-in-callbacks\" style=\"position:relative;\"><a href=\"#this-parameters-in-callbacks\" aria-label=\"this parameters in callbacks 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>this</code> parameters in callbacks</h2>\n<p>Libraries can also use <code>this</code> parameters to declare how callbacks will be invoked.</p>\n<h5 id=\"example-7\" style=\"position:relative;\"><a href=\"#example-7\" aria-label=\"example 7 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>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\"> UIElement {</span>\n<span style=\"color: #000000\">    addClickListener(onclick: (this: void, e: Event) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void): void;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><code>this: void</code> means that <code>addClickListener</code> expects <code>onclick</code> to be a function that does not require a <code>this</code> type.</p>\n<p>Now if you annotate calling code with <code>this</code>:</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\"> Handler {</span>\n<span style=\"color: #000000\">    info: string;</span>\n<span style=\"color: #000000\">    onClickBad(this: Handler, e: Event) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #008000\">// oops, used this here. using this callback would crash at runtime</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.info = e.message;</span>\n<span style=\"color: #000000\">    };</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> h = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Handler();</span>\n<span style=\"color: #000000\">uiElement.addClickListener(h.onClickBad); </span><span style=\"color: #008000\">// error!</span></code></div></pre>\n<h2 id=\"--noimplicitthis\" style=\"position:relative;\"><a href=\"#--noimplicitthis\" aria-label=\"  noimplicitthis 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>--noImplicitThis</code></h2>\n<p>A new flag is also added in TypeScript 2.0 to flag all uses of <code>this</code> in functions without an explicit type annotation.</p>\n<h2 id=\"glob-support-in-tsconfigjson\" style=\"position:relative;\"><a href=\"#glob-support-in-tsconfigjson\" aria-label=\"glob support in tsconfigjson 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>Glob support in <code>tsconfig.json</code></h2>\n<p>Glob support is here!! Glob support has been <a href=\"https://github.com/Microsoft/TypeScript/issues/1927\">one of the most requested features</a>.</p>\n<p>Glob-like file patterns are supported two properties <code>\"include\"</code> and <code>\"exclude\"</code>.</p>\n<h5 id=\"example-8\" style=\"position:relative;\"><a href=\"#example-8\" aria-label=\"example 8 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"module\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"commonjs\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"noImplicitAny\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"removeComments\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"preserveConstEnums\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"outFile\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"../../built/local/tsc.js\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"sourceMap\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span>\n<span style=\"color: #000000\">    },</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"include\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"src/**/*\"</span>\n<span style=\"color: #000000\">    ],</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"exclude\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"node_modules\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"**/*.spec.ts\"</span>\n<span style=\"color: #000000\">    ]</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>The supported glob wildcards are:</p>\n<ul>\n<li><code>*</code> matches zero or more characters (excluding directory separators)</li>\n<li><code>?</code> matches any one character (excluding directory separators)</li>\n<li><code>**/</code> recursively matches any subdirectory</li>\n</ul>\n<p>If a segment of a glob pattern includes only <code>*</code> or <code>.*</code>, then only files with supported extensions are included (e.g. <code>.ts</code>, <code>.tsx</code>, and <code>.d.ts</code> by default with <code>.js</code> and <code>.jsx</code> if <code>allowJs</code> is set to true).</p>\n<p>If the <code>\"files\"</code> and <code>\"include\"</code> are both left unspecified, the compiler defaults to including all TypeScript (<code>.ts</code>, <code>.d.ts</code> and <code>.tsx</code>) files in the containing directory and subdirectories except those excluded using the <code>\"exclude\"</code> property. JS files (<code>.js</code> and <code>.jsx</code>) are also included if <code>allowJs</code> is set to true.</p>\n<p>If the <code>\"files\"</code> or <code>\"include\"</code> properties are specified, the compiler will instead include the union of the files included by those two properties.\nFiles in the directory specified using the <code>\"outDir\"</code> compiler option are always excluded unless explicitly included via the <code>\"files\"</code> property (even when the ”<code>exclude</code>” property is specified).</p>\n<p>Files included using <code>\"include\"</code> can be filtered using the <code>\"exclude\"</code> property.\nHowever, files included explicitly using the <code>\"files\"</code> property are always included regardless of <code>\"exclude\"</code>.\nThe <code>\"exclude\"</code> property defaults to excluding the <code>node_modules</code>, <code>bower_components</code>, and <code>jspm_packages</code> directories when not specified.</p>\n<h2 id=\"module-resolution-enhancements-baseurl-path-mapping-rootdirs-and-tracing\" style=\"position:relative;\"><a href=\"#module-resolution-enhancements-baseurl-path-mapping-rootdirs-and-tracing\" aria-label=\"module resolution enhancements baseurl path mapping rootdirs and tracing 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>Module resolution enhancements: BaseUrl, Path mapping, rootDirs and tracing</h2>\n<p>TypeScript 2.0 provides a set of additional module resolution knops to <em>inform</em> the compiler where to find declarations for a given module.</p>\n<p>See <a href=\"http://www.typescriptlang.org/docs/handbook/module-resolution.html\">Module Resolution</a> documentation for more details.</p>\n<h2 id=\"base-url\" style=\"position:relative;\"><a href=\"#base-url\" aria-label=\"base url 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>Base URL</h2>\n<p>Using a <code>baseUrl</code> is a common practice in applications using AMD module loaders where modules are “deployed” to a single folder at run-time.\nAll module imports with non-relative names are assumed to be relative to the <code>baseUrl</code>.</p>\n<h5 id=\"example-9\" style=\"position:relative;\"><a href=\"#example-9\" aria-label=\"example 9 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"baseUrl\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./modules\"</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Now imports to <code>\"moduleA\"</code> would be looked up in <code>./modules/moduleA</code></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> A </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"moduleA\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h2 id=\"path-mapping\" style=\"position:relative;\"><a href=\"#path-mapping\" aria-label=\"path mapping 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>Path mapping</h2>\n<p>Sometimes modules are not directly located under <em>baseUrl</em>.\nLoaders use a mapping configuration to map module names to files at run-time, see <a href=\"http://requirejs.org/docs/api.html#config-paths\">RequireJs documentation</a> and <a href=\"https://github.com/systemjs/systemjs/blob/master/docs/overview.md#map-config\">SystemJS documentation</a>.</p>\n<p>The TypeScript compiler supports the declaration of such mappings using <code>\"paths\"</code> property in <code>tsconfig.json</code> files.</p>\n<h5 id=\"example-10\" style=\"position:relative;\"><a href=\"#example-10\" aria-label=\"example 10 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>Example</h5>\n<p>For instance, an import to a module <code>\"jquery\"</code> would be translated at runtime to <code>\"node_modules/jquery/dist/jquery.slim.min.js\"</code>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"baseUrl\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./node_modules\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"paths\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">      </span><span style=\"color: #0451A5\">\"jquery\"</span><span style=\"color: #000000\">: [</span><span style=\"color: #A31515\">\"jquery/dist/jquery.slim.min\"</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Using <code>\"paths\"</code> also allow for more sophisticated mappings including multiple fall back locations.\nConsider a project configuration where only some modules are available in one location, and the rest are in another.</p>\n<h2 id=\"virtual-directories-with-rootdirs\" style=\"position:relative;\"><a href=\"#virtual-directories-with-rootdirs\" aria-label=\"virtual directories with rootdirs 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>Virtual Directories with <code>rootDirs</code></h2>\n<p>Using ‘rootDirs’, you can inform the compiler of the <em>roots</em> making up this “virtual” directory;\nand thus the compiler can resolve relative modules imports within these “virtual” directories <em>as if</em> were merged together in one directory.</p>\n<h5 id=\"example-11\" style=\"position:relative;\"><a href=\"#example-11\" aria-label=\"example 11 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>Example</h5>\n<p>Given this project structure:</p>\n<pre><code class=\"language-tree\"> src\n └── views\n     └── view1.ts (imports './template1')\n     └── view2.ts\n\n generated\n └── templates\n         └── views\n             └── template1.ts (imports './view2')\n</code></pre>\n<p>A build step will copy the files in <code>/src/views</code> and <code>/generated/templates/views</code> to the same directory in the output.\nAt run-time, a view can expect its template to exist next to it, and thus should import it using a relative name as <code>\"./template\"</code>.</p>\n<p><code>\"rootDirs\"</code> specify a list of <em>roots</em> whose contents are expected to merge at run-time.\nSo following our example, the <code>tsconfig.json</code> file should look like:</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"rootDirs\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">      </span><span style=\"color: #A31515\">\"src/views\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">      </span><span style=\"color: #A31515\">\"generated/templates/views\"</span>\n<span style=\"color: #000000\">    ]</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"tracing-module-resolution\" style=\"position:relative;\"><a href=\"#tracing-module-resolution\" aria-label=\"tracing module resolution 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>Tracing module resolution</h2>\n<p><code>--traceResolution</code> offers a handy way to understand how modules have been resolved by the compiler.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">tsc --traceResolution</span></code></div></pre>\n<h2 id=\"shorthand-ambient-module-declarations\" style=\"position:relative;\"><a href=\"#shorthand-ambient-module-declarations\" aria-label=\"shorthand ambient module 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>Shorthand ambient module declarations</h2>\n<p>If you don’t want to take the time to write out declarations before using a new module, you can now just use a shorthand declaration to get started quickly.</p>\n<h5 id=\"declarationsdts\" style=\"position:relative;\"><a href=\"#declarationsdts\" aria-label=\"declarationsdts 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>declarations.d.ts</h5>\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\">module</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"hot-new-module\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>All imports from a shorthand module will have the any type.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> x, {y} </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"hot-new-module\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">x(y);</span></code></div></pre>\n<h2 id=\"wildcard-character-in-module-names\" style=\"position:relative;\"><a href=\"#wildcard-character-in-module-names\" aria-label=\"wildcard character in 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>Wildcard character in module names</h2>\n<p>Importing none-code resources using module loaders extension (e.g. <a href=\"https://github.com/amdjs/amdjs-api/blob/master/LoaderPlugins.md\">AMD</a> or <a href=\"https://github.com/systemjs/systemjs/blob/master/docs/creating-plugins.md\">SystemJS</a>) has not been easy before;\npreviously an ambient module declaration had to be defined for each resource.</p>\n<p>TypeScript 2.0 supports the use of the wildcard character (<code>*</code>) to declare a “family” of module names;\nthis way, a declaration is only required once for an extension, and not for every resource.</p>\n<h5 id=\"example-12\" style=\"position:relative;\"><a href=\"#example-12\" aria-label=\"example 12 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>Example</h5>\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\">module</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"*!text\"</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> content: string;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">default</span><span style=\"color: #000000\"> content;</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #008000\">// Some do it the other way around.</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">module</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"json!*\"</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> value: any;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">default</span><span style=\"color: #000000\"> value;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Now you can import things that match <code>\"*!text\"</code> or <code>\"json!*\"</code>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> fileContent </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"./xyz.txt!text\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> data </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"json!http://example.com/data.json\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">console.log(data, fileContent);</span></code></div></pre>\n<p>Wildcard module names can be even more useful when migrating from an un-typed code base.\nCombined with Shorthand ambient module declarations, a set of modules can be easily declared as <code>any</code>.</p>\n<h5 id=\"example-13\" style=\"position:relative;\"><a href=\"#example-13\" aria-label=\"example 13 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>Example</h5>\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\">module</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"myLibrary/*\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>All imports to any module under <code>myLibrary</code> would be considered to have the type <code>any</code> by the compiler;\nthus, shutting down any checking on the shapes or types of these modules.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { readFile } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"myLibrary/fileSystem/readFile`</span><span style=\"color: #CD3131\">;</span>\n\n<span style=\"color: #000000\">readFile(); </span><span style=\"color: #008000\">// readFile is 'any'</span></code></div></pre>\n<h2 id=\"support-for-umd-module-definitions\" style=\"position:relative;\"><a href=\"#support-for-umd-module-definitions\" aria-label=\"support for umd module definitions 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>Support for UMD module definitions</h2>\n<p>Some libraries are designed to be used in many module loaders, or with no module loading (global variables).\nThese are known as <a href=\"https://github.com/umdjs/umd\">UMD</a> or <a href=\"http://isomorphic.net\">Isomorphic</a> modules.\nThese libraries can be accessed through either an import or a global variable.</p>\n<p>For example:</p>\n<h5 id=\"math-libdts\" style=\"position:relative;\"><a href=\"#math-libdts\" aria-label=\"math libdts 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>math-lib.d.ts</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\">const</span><span style=\"color: #000000\"> isPrime(x: number): boolean;</span>\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">namespace</span><span style=\"color: #000000\"> mathLib;</span></code></div></pre>\n<p>The library can then be used as an import within modules:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { isPrime } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"math-lib\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">isPrime(</span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">mathLib.isPrime(</span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// ERROR: can't use the global definition from inside a module</span></code></div></pre>\n<p>It can also be used as a global variable, but only inside of a script.\n(A script is a file with no imports or exports.)</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">mathLib.isPrime(</span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">);</span></code></div></pre>\n<h2 id=\"optional-class-properties\" style=\"position:relative;\"><a href=\"#optional-class-properties\" aria-label=\"optional class properties 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>Optional class properties</h2>\n<p>Optional properties and methods can now be declared in classes, similar to what is already permitted in interfaces.</p>\n<h5 id=\"example-14\" style=\"position:relative;\"><a href=\"#example-14\" aria-label=\"example 14 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>Example</h5>\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\"> Bar {</span>\n<span style=\"color: #000000\">    a: number;</span>\n<span style=\"color: #000000\">    b?: number;</span>\n<span style=\"color: #000000\">    f() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    g?(): number;  </span><span style=\"color: #008000\">// Body of optional method can be omitted</span>\n<span style=\"color: #000000\">    h?() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>When compiled in <code>--strictNullChecks</code> mode, optional properties and methods automatically have <code>undefined</code> included in their type. Thus, the <code>b</code> property above is of type <code>number | undefined</code> and the <code>g</code> method above is of type <code>(() => number) | undefined</code>.\nType guards can be used to strip away the <code>undefined</code> part of the 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\"> test(x: Bar) {</span>\n<span style=\"color: #000000\">    x.a;  </span><span style=\"color: #008000\">// number</span>\n<span style=\"color: #000000\">    x.b;  </span><span style=\"color: #008000\">// number | undefined</span>\n<span style=\"color: #000000\">    x.f;  </span><span style=\"color: #008000\">// () =&gt; number</span>\n<span style=\"color: #000000\">    x.g;  </span><span style=\"color: #008000\">// (() =&gt; number) | undefined</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> f1 = x.f();            </span><span style=\"color: #008000\">// number</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> g1 = x.g && x.g();     </span><span style=\"color: #008000\">// number | undefined</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> g2 = x.g ? x.g() : </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// number</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"private-and-protected-constructors\" style=\"position:relative;\"><a href=\"#private-and-protected-constructors\" aria-label=\"private and protected constructors 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>Private and Protected Constructors</h2>\n<p>A class constructor may be marked <code>private</code> or <code>protected</code>.\nA class with private constructor cannot be instantiated outside the class body, and cannot be extended.\nA class with protected constructor cannot be instantiated outside the class body, but can be extended.</p>\n<h5 id=\"example-15\" style=\"position:relative;\"><a href=\"#example-15\" aria-label=\"example 15 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>Example</h5>\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\"> Singleton {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">private</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">static</span><span style=\"color: #000000\"> instance: Singleton;</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">private</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">() { }</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">static</span><span style=\"color: #000000\"> getInstance() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (!Singleton.instance) {</span>\n<span style=\"color: #000000\">            Singleton.instance = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Singleton();</span>\n<span style=\"color: #000000\">        }</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> Singleton.instance;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> e = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Singleton(); </span><span style=\"color: #008000\">// Error: constructor of 'Singleton' is private.</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v = Singleton.getInstance();</span></code></div></pre>\n<h2 id=\"abstract-properties-and-accessors\" style=\"position:relative;\"><a href=\"#abstract-properties-and-accessors\" aria-label=\"abstract properties and accessors 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>Abstract properties and accessors</h2>\n<p>An abstract class can declare abstract properties and/or accessors.\nAny sub class will need to declare the abstract properties or be marked as abstract.\nAbstract properties cannot have an initializer.\nAbstract accessors cannot have bodies.</p>\n<h5 id=\"example-16\" style=\"position:relative;\"><a href=\"#example-16\" aria-label=\"example 16 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">abstract</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Base {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">abstract</span><span style=\"color: #000000\"> name: string;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">abstract</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">get</span><span style=\"color: #000000\"> value();</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">abstract</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">set</span><span style=\"color: #000000\"> value(v: number);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Derived </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Base {</span>\n<span style=\"color: #000000\">    name = </span><span style=\"color: #A31515\">\"derived\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #000000\">    value = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"implicit-index-signatures\" style=\"position:relative;\"><a href=\"#implicit-index-signatures\" aria-label=\"implicit index signatures 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>Implicit index signatures</h2>\n<p>An object literal type is now assignable to a type with an index signature if all known properties in the object literal are assignable to that index signature. This makes it possible to pass a variable that was initialized with an object literal as parameter to a function that expects a map or dictionary:</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\"> httpService(path: string, headers: { [x: string]: string }) { }</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> headers = {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #A31515\">\"Content-Type\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"application/x-www-form-urlencoded\"</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #000000\">httpService(</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">, { </span><span style=\"color: #A31515\">\"Content-Type\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"application/x-www-form-urlencoded\"</span><span style=\"color: #000000\"> });  </span><span style=\"color: #008000\">// Ok</span>\n<span style=\"color: #000000\">httpService(</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">, headers);  </span><span style=\"color: #008000\">// Now ok, previously wasn't</span></code></div></pre>\n<h2 id=\"including-built-in-type-declarations-with---lib\" style=\"position:relative;\"><a href=\"#including-built-in-type-declarations-with---lib\" aria-label=\"including built in type declarations with   lib 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>Including built-in type declarations with <code>--lib</code></h2>\n<p>Getting to ES6/ES2015 built-in API declarations were only limited to <code>target: ES6</code>.\nEnter <code>--lib</code>; with <code>--lib</code> you can specify a list of built-in API declaration groups that you can chose to include in your project.\nFor instance, if you expect your runtime to have support for <code>Map</code>, <code>Set</code> and <code>Promise</code> (e.g. most evergreen browsers today), just include <code>--lib es2015.collection,es2015.promise</code>.\nSimilarly you can exclude declarations you do not want to include in your project, e.g. DOM if you are working on a node project using <code>--lib es5,es6</code>.</p>\n<p>Here is a list of available API groups:</p>\n<ul>\n<li>dom</li>\n<li>webworker</li>\n<li>es5</li>\n<li>es6 / es2015</li>\n<li>es2015.core</li>\n<li>es2015.collection</li>\n<li>es2015.iterable</li>\n<li>es2015.promise</li>\n<li>es2015.proxy</li>\n<li>es2015.reflect</li>\n<li>es2015.generator</li>\n<li>es2015.symbol</li>\n<li>es2015.symbol.wellknown</li>\n<li>es2016</li>\n<li>es2016.array.include</li>\n<li>es2017</li>\n<li>es2017.object</li>\n<li>es2017.sharedmemory</li>\n<li>scripthost</li>\n</ul>\n<h5 id=\"example-17\" style=\"position:relative;\"><a href=\"#example-17\" aria-label=\"example 17 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">bash</div><div class='code-container'><code><span style=\"color: #000000\">tsc --target es5 --lib es5,es2015.promise</span></code></div></pre>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #A31515\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"lib\"</span><span style=\"color: #000000\">: [</span><span style=\"color: #A31515\">\"es5\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"es2015.promise\"</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"flag-unused-declarations-with---nounusedparameters-and---nounusedlocals\" style=\"position:relative;\"><a href=\"#flag-unused-declarations-with---nounusedparameters-and---nounusedlocals\" aria-label=\"flag unused declarations with   nounusedparameters and   nounusedlocals 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>Flag unused declarations with <code>--noUnusedParameters</code> and <code>--noUnusedLocals</code></h2>\n<p>TypeScript 2.0 has two new flags to help you maintain a clean code base.\n<code>--noUnusedParameters</code> flags any unused function or method parameters errors.\n<code>--noUnusedLocals</code> flags any unused local (un-exported) declaration like variables, functions, classes, imports, etc…\nAlso, unused private members of a class would be flagged as errors under <code>--noUnusedLocals</code>.</p>\n<h5 id=\"example-18\" style=\"position:relative;\"><a href=\"#example-18\" aria-label=\"example 18 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>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> B, { readFile } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"./b\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #008000\">//     ^ Error: `B` declared but never used</span>\n<span style=\"color: #000000\">readFile();</span>\n\n\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> write(message: string, args: string[]) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">//                                 ^^^^  Error: 'arg' declared but never used.</span>\n<span style=\"color: #000000\">    console.log(message);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Parameters declaration with names starting with <code>_</code> are exempt from the unused parameter checking.\ne.g.:</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\"> returnNull(_a) { </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"module-identifiers-allow-for-js-extension\" style=\"position:relative;\"><a href=\"#module-identifiers-allow-for-js-extension\" aria-label=\"module identifiers allow for js extension 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>Module identifiers allow for <code>.js</code> extension</h2>\n<p>Before TypeScript 2.0, a module identifier was always assumed to be extension-less;\nfor instance, given an import as <code>import d from \"./moduleA.js\"</code>, the compiler looked up the definition of <code>\"moduleA.js\"</code> in <code>./moduleA.js.ts</code> or <code>./moduleA.js.d.ts</code>.\nThis made it hard to use bundling/loading tools like <a href=\"https://github.com/systemjs/systemjs\">SystemJS</a> that expect URI’s in their module identifier.</p>\n<p>With TypeScript 2.0, the compiler will look up definition of <code>\"moduleA.js\"</code> in  <code>./moduleA.ts</code> or <code>./moduleA.d.t</code>.</p>\n<h2 id=\"support-target--es5-with-module-es6\" style=\"position:relative;\"><a href=\"#support-target--es5-with-module-es6\" aria-label=\"support target  es5 with module es6 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>Support ‘target : es5’ with ‘module: es6’</h2>\n<p>Previously flagged as an invalid flag combination, <code>target: es5</code> and ‘module: es6’ is now supported.\nThis should facilitate using ES2015-based tree shakers like <a href=\"https://github.com/rollup/rollup\">rollup</a>.</p>\n<h2 id=\"trailing-commas-in-function-parameter-and-argument-lists\" style=\"position:relative;\"><a href=\"#trailing-commas-in-function-parameter-and-argument-lists\" aria-label=\"trailing commas in function parameter and argument lists 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>Trailing commas in function parameter and argument lists</h2>\n<p>Trailing comma in function parameter and argument lists are now allowed.\nThis is an implementation for a <a href=\"https://jeffmo.github.io/es-trailing-function-commas/\">Stage-3 ECMAScript proposal</a> that emits down to valid ES3/ES5/ES6.</p>\n<h5 id=\"example-19\" style=\"position:relative;\"><a href=\"#example-19\" aria-label=\"example 19 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>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\"> foo(</span>\n<span style=\"color: #000000\">  bar: Bar,</span>\n<span style=\"color: #000000\">  baz: Baz, </span><span style=\"color: #008000\">// trailing commas are OK in parameter lists</span>\n<span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// Implementation...</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">foo(</span>\n<span style=\"color: #000000\">  bar,</span>\n<span style=\"color: #000000\">  baz, </span><span style=\"color: #008000\">// and in argument lists</span>\n<span style=\"color: #000000\">);</span></code></div></pre>\n<h2 id=\"new---skiplibcheck\" style=\"position:relative;\"><a href=\"#new---skiplibcheck\" aria-label=\"new   skiplibcheck 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>New <code>--skipLibCheck</code></h2>\n<p>TypeScript 2.0 adds a new <code>--skipLibCheck</code> compiler option that causes type checking of declaration files (files with extension <code>.d.ts</code>) to be skipped.\nWhen a program includes large declaration files, the compiler spends a lot of time type checking declarations that are already known to not contain errors, and compile times may be significantly shortened by skipping declaration file type checks.</p>\n<p>Since declarations in one file can affect type checking in other files, some errors may not be detected when <code>--skipLibCheck</code> is specified.\nFor example, if a non-declaration file augments a type declared in a declaration file, errors may result that are only reported when the declaration file is checked.\nHowever, in practice such situations are rare.</p>\n<h2 id=\"allow-duplicate-identifiers-across-declarations\" style=\"position:relative;\"><a href=\"#allow-duplicate-identifiers-across-declarations\" aria-label=\"allow duplicate identifiers across 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>Allow duplicate identifiers across declarations</h2>\n<p>This has been one common source of duplicate definition errors.\nMultiple declaration files defining the same members on interfaces.</p>\n<p>TypeScript 2.0 relaxes this constraint and allows duplicate identifiers across blocks, as long as they have <em>identical</em> types.</p>\n<p>Within the same block duplicate definitions are still disallowed.</p>\n<h5 id=\"example-20\" style=\"position:relative;\"><a href=\"#example-20\" aria-label=\"example 20 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>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\"> Error {</span>\n<span style=\"color: #000000\">    stack?: string;</span>\n<span style=\"color: #000000\">}</span>\n\n\n<span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Error {</span>\n<span style=\"color: #000000\">    code?: string;</span>\n<span style=\"color: #000000\">    path?: string;</span>\n<span style=\"color: #000000\">    stack?: string;  </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"new---declarationdir\" style=\"position:relative;\"><a href=\"#new---declarationdir\" aria-label=\"new   declarationdir 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>New <code>--declarationDir</code></h2>\n<p><code>--declarationDir</code> allows for generating declaration files in a different location than JavaScript files.</p>","headings":[{"value":"Null- and undefined-aware types","depth":2},{"value":"--strictNullChecks","depth":2},{"value":"Example","depth":5},{"value":"Assigned-before-use checking","depth":2},{"value":"Example","depth":5},{"value":"Optional parameters and properties","depth":2},{"value":"Non-null and non-undefined type guards","depth":2},{"value":"Example","depth":5},{"value":"Dotted names in type guards","depth":2},{"value":"Example","depth":5},{"value":"Expression operators","depth":2},{"value":"Type widening","depth":2},{"value":"Non-null assertion operator","depth":2},{"value":"Compatibility","depth":2},{"value":"Control flow based type analysis","depth":2},{"value":"Example","depth":5},{"value":"Tagged union types","depth":2},{"value":"Example","depth":5},{"value":"The never type","depth":2},{"value":"Read-only properties and index signatures","depth":2},{"value":"Example","depth":5},{"value":"Specifying the type of this for functions","depth":2},{"value":"this parameters in callbacks","depth":2},{"value":"Example","depth":5},{"value":"--noImplicitThis","depth":2},{"value":"Glob support in tsconfig.json","depth":2},{"value":"Example","depth":5},{"value":"Module resolution enhancements: BaseUrl, Path mapping, rootDirs and tracing","depth":2},{"value":"Base URL","depth":2},{"value":"Example","depth":5},{"value":"Path mapping","depth":2},{"value":"Example","depth":5},{"value":"Virtual Directories with rootDirs","depth":2},{"value":"Example","depth":5},{"value":"Tracing module resolution","depth":2},{"value":"Shorthand ambient module declarations","depth":2},{"value":"declarations.d.ts","depth":5},{"value":"Wildcard character in module names","depth":2},{"value":"Example","depth":5},{"value":"Example","depth":5},{"value":"Support for UMD module definitions","depth":2},{"value":"math-lib.d.ts","depth":5},{"value":"Optional class properties","depth":2},{"value":"Example","depth":5},{"value":"Private and Protected Constructors","depth":2},{"value":"Example","depth":5},{"value":"Abstract properties and accessors","depth":2},{"value":"Example","depth":5},{"value":"Implicit index signatures","depth":2},{"value":"Including built-in type declarations with --lib","depth":2},{"value":"Example","depth":5},{"value":"Flag unused declarations with --noUnusedParameters and --noUnusedLocals","depth":2},{"value":"Example","depth":5},{"value":"Module identifiers allow for .js extension","depth":2},{"value":"Support ‘target : es5’ with ‘module: es6’","depth":2},{"value":"Trailing commas in function parameter and argument lists","depth":2},{"value":"Example","depth":5},{"value":"New --skipLibCheck","depth":2},{"value":"Allow duplicate identifiers across declarations","depth":2},{"value":"Example","depth":5},{"value":"New --declarationDir","depth":2}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-2-0.html","title":"TypeScript 2.0"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-2-0.html","isOldHandbook":true}}}