{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-2-1.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":"1da7ba61-f524-509e-b072-0fd12e9ea4a1","excerpt":"keyof and Lookup Types In JavaScript it is fairly common to have APIs that expect property names as parameters, but so far it hasn’t been possible to express…","html":"<h2 id=\"keyof-and-lookup-types\" style=\"position:relative;\"><a href=\"#keyof-and-lookup-types\" aria-label=\"keyof and lookup 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><code>keyof</code> and Lookup Types</h2>\n<p>In JavaScript it is fairly common to have APIs that expect property names as parameters, but so far it hasn’t been possible to express the type relationships that occur in those APIs.</p>\n<p>Enter Index Type Query or <code>keyof</code>;\nAn indexed type query <code>keyof T</code> yields the type of permitted property names for <code>T</code>.\nA <code>keyof T</code> type is considered a subtype of <code>string</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: #0000FF\">interface</span><span style=\"color: #000000\"> Person {</span>\n<span style=\"color: #000000\">    name: string;</span>\n<span style=\"color: #000000\">    age: number;</span>\n<span style=\"color: #000000\">    location: string;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> K1 = </span><span style=\"color: #0000FF\">keyof</span><span style=\"color: #000000\"> Person; </span><span style=\"color: #008000\">// \"name\" | \"age\" | \"location\"</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> K2 = </span><span style=\"color: #0000FF\">keyof</span><span style=\"color: #000000\"> Person[];  </span><span style=\"color: #008000\">// \"length\" | \"push\" | \"pop\" | \"concat\" | ...</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> K3 = </span><span style=\"color: #0000FF\">keyof</span><span style=\"color: #000000\"> { [x: string]: Person };  </span><span style=\"color: #008000\">// string</span></code></div></pre>\n<p>The dual of this is <em>indexed access types</em>, also called <em>lookup types</em>.\nSyntactically, they look exactly like an element access, but are written as types:</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: #0000FF\">type</span><span style=\"color: #000000\"> P1 = Person[</span><span style=\"color: #A31515\">\"name\"</span><span style=\"color: #000000\">];  </span><span style=\"color: #008000\">// string</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> P2 = Person[</span><span style=\"color: #A31515\">\"name\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"age\"</span><span style=\"color: #000000\">];  </span><span style=\"color: #008000\">// string | number</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> P3 = string[</span><span style=\"color: #A31515\">\"charAt\"</span><span style=\"color: #000000\">];  </span><span style=\"color: #008000\">// (pos: number) =&gt; string</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> P4 = string[][</span><span style=\"color: #A31515\">\"push\"</span><span style=\"color: #000000\">];  </span><span style=\"color: #008000\">// (...items: string[]) =&gt; number</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> P5 = string[][</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">];  </span><span style=\"color: #008000\">// string</span></code></div></pre>\n<p>You can use this pattern with other parts of the type system to get type-safe lookups.</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\"> getProperty&lt;T, K </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">keyof</span><span style=\"color: #000000\"> T&gt;(obj: T, key: K) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> obj[key];  </span><span style=\"color: #008000\">// Inferred type is T[K]</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> setProperty&lt;T, K </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">keyof</span><span style=\"color: #000000\"> T&gt;(obj: T, key: K, value: T[K]) {</span>\n<span style=\"color: #000000\">    obj[key] = value;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x = { foo: </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">, bar: </span><span style=\"color: #A31515\">\"hello!\"</span><span style=\"color: #000000\"> };</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> foo = getProperty(x, </span><span style=\"color: #A31515\">\"foo\"</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// number</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> bar = getProperty(x, </span><span style=\"color: #A31515\">\"bar\"</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// string</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> oops = getProperty(x, </span><span style=\"color: #A31515\">\"wargarbl\"</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error! \"wargarbl\" is not \"foo\" | \"bar\"</span>\n\n<span style=\"color: #000000\">setProperty(x, </span><span style=\"color: #A31515\">\"foo\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error!, string expected number</span></code></div></pre>\n<h2 id=\"mapped-types\" style=\"position:relative;\"><a href=\"#mapped-types\" aria-label=\"mapped 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>Mapped Types</h2>\n<p>One common task is to take an existing type and make each of its properties entirely optional.\nLet’s say we have a <code>Person</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Person {</span>\n<span style=\"color: #000000\">    name: string;</span>\n<span style=\"color: #000000\">    age: number;</span>\n<span style=\"color: #000000\">    location: string;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>A partial version of it would be:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> PartialPerson {</span>\n<span style=\"color: #000000\">    name?: string;</span>\n<span style=\"color: #000000\">    age?: number;</span>\n<span style=\"color: #000000\">    location?: string;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>with Mapped types, <code>PartialPerson</code> can be written as a generalized transformation on the type <code>Person</code> as:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Partial&lt;T&gt; = {</span>\n<span style=\"color: #000000\">    [P </span><span style=\"color: #0000FF\">in</span><span style=\"color: #000000\"> keyof T]?: T[P];</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> PartialPerson = Partial&lt;Person&gt;;</span></code></div></pre>\n<p>Mapped types are produced by taking a union of literal types, and computing a set of properties for a new object type.\nThey’re like <a href=\"https://docs.python.org/2/tutorial/datastructures.html#nested-list-comprehensions\">list comprehensions in Python</a>, but instead of producing new elements in a list, they produce new properties in a type.</p>\n<p>In addition to <code>Partial</code>, Mapped Types can express many useful transformations on types:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Keep types the same, but make each property to be read-only.</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Readonly&lt;T&gt; = {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">readonly</span><span style=\"color: #000000\"> [P </span><span style=\"color: #0000FF\">in</span><span style=\"color: #000000\"> keyof T]: T[P];</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #008000\">// Same property names, but make the value a promise instead of a concrete one</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Deferred&lt;T&gt; = {</span>\n<span style=\"color: #000000\">    [P </span><span style=\"color: #0000FF\">in</span><span style=\"color: #000000\"> keyof T]: Promise&lt;T[P]&gt;;</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #008000\">// Wrap proxies around properties of T</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Proxify&lt;T&gt; = {</span>\n<span style=\"color: #000000\">    [P </span><span style=\"color: #0000FF\">in</span><span style=\"color: #000000\"> keyof T]: { get(): T[P]; set(v: T[P]): void }</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<h2 id=\"partial-readonly-record-and-pick\" style=\"position:relative;\"><a href=\"#partial-readonly-record-and-pick\" aria-label=\"partial readonly record and pick 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>Partial</code>, <code>Readonly</code>, <code>Record</code>, and <code>Pick</code></h2>\n<p><code>Partial</code> and <code>Readonly</code>, as described earlier, are very useful constructs.\nYou can use them to describe some common JS routines like:</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\"> assign&lt;T&gt;(obj: T, props: Partial&lt;T&gt;): void;</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> freeze&lt;T&gt;(obj: T): Readonly&lt;T&gt;;</span></code></div></pre>\n<p>Because of that, they are now included by default in the standard library.</p>\n<p>We’re also including two other utility types as well: <code>Record</code> and <code>Pick</code>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// From T pick a set of properties K</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> pick&lt;T, K </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">keyof</span><span style=\"color: #000000\"> T&gt;(obj: T, ...keys: K[]): Pick&lt;T, K&gt;;</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> nameAndAgeOnly = pick(person, </span><span style=\"color: #A31515\">\"name\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"age\"</span><span style=\"color: #000000\">);  </span><span style=\"color: #008000\">// { name: string, age: number }</span></code></div></pre>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// For every properties K of type T, transform it to U</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> mapObject&lt;K </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> string, T, U&gt;(obj: Record&lt;K, T&gt;, f: (x: T) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> U): Record&lt;K, U&gt;</span>\n\n<span style=\"color: #000000\">const names = { foo: </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">, bar: </span><span style=\"color: #A31515\">\"world\"</span><span style=\"color: #000000\">, baz: </span><span style=\"color: #A31515\">\"bye\"</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> lengths = mapObject(names, s </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> s.length);  </span><span style=\"color: #008000\">// { foo: number, bar: number, baz: number }</span></code></div></pre>\n<h2 id=\"object-spread-and-rest\" style=\"position:relative;\"><a href=\"#object-spread-and-rest\" aria-label=\"object spread and rest 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>Object Spread and Rest</h2>\n<p>TypeScript 2.1 brings support for <a href=\"https://github.com/sebmarkbage/ecmascript-rest-spread\">ESnext Spread and Rest</a>.</p>\n<p>Similar to array spread, spreading an object can be handy to get a shallow copy:</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\"> copy = { ...original };</span></code></div></pre>\n<p>Similarly, you can merge several different objects.\nIn the following example, <code>merged</code> will have properties from <code>foo</code>, <code>bar</code>, and <code>baz</code>.</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\"> merged = { ...foo, ...bar, ...baz };</span></code></div></pre>\n<p>You can also override existing properties and add new ones:</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\"> obj = { x: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, y: </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> newObj = {...obj, z: </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">, y: </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">}; </span><span style=\"color: #008000\">// { x: number, y: number, z: number }</span></code></div></pre>\n<p>The order of specifying spread operations determines what properties end up in the resulting object;\nproperties in later spreads “win out” over previously created properties.</p>\n<p>Object rests are the dual of object spreads, in that they can extract any extra properties that don’t get picked up when destructuring an element:</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\"> obj = { x: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, y: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, z: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> { z, ...obj1 } = obj;</span>\n<span style=\"color: #000000\">obj1; </span><span style=\"color: #008000\">// {x: number, y:number};</span></code></div></pre>\n<h2 id=\"downlevel-async-functions\" style=\"position:relative;\"><a href=\"#downlevel-async-functions\" aria-label=\"downlevel async 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>Downlevel Async Functions</h2>\n<p>This feature was supported before TypeScript 2.1, but only when targeting ES6/ES2015.\nTypeScript 2.1 brings the capability to ES3 and ES5 run-times, meaning you’ll be free to take advantage of it no matter what environment you’re using.</p>\n<blockquote>\n<p>Note: first, we need to make sure our run-time has an ECMAScript-compliant <code>Promise</code> available globally.\nThat might involve grabbing <a href=\"https://github.com/stefanpenner/es6-promise\">a polyfill</a> for <code>Promise</code>, or relying on one that you might have in the run-time that you’re targeting.\nWe also need to make sure that TypeScript knows <code>Promise</code> exists by setting your <code>lib</code> flag to something like <code>\"dom\", \"es2015\"</code> or <code>\"dom\", \"es2015.promise\", \"es5\"</code></p>\n</blockquote>\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<h5 id=\"tsconfigjson\" style=\"position:relative;\"><a href=\"#tsconfigjson\" aria-label=\"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>tsconfig.json</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\">\"lib\"</span><span style=\"color: #000000\">: [</span><span style=\"color: #A31515\">\"dom\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"es2015.promise\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"es5\"</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h5 id=\"dramaticwelcomets\" style=\"position:relative;\"><a href=\"#dramaticwelcomets\" aria-label=\"dramaticwelcomets 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>dramaticWelcome.ts</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\"> delay(milliseconds: number) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Promise&lt;void&gt;(resolve </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">        setTimeout(resolve, milliseconds);</span>\n<span style=\"color: #000000\">    });</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">async</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> dramaticWelcome() {</span>\n<span style=\"color: #000000\">    console.log(</span><span style=\"color: #A31515\">\"Hello\"</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">for</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> i = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">; i &lt; </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">; i++) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">await</span><span style=\"color: #000000\"> delay(</span><span style=\"color: #09835A\">500</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">        console.log(</span><span style=\"color: #A31515\">\".\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">    }</span>\n\n<span style=\"color: #000000\">    console.log(</span><span style=\"color: #A31515\">\"World!\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">dramaticWelcome();</span></code></div></pre>\n<p>Compiling and running the output should result in the correct behavior on an ES3/ES5 engine.</p>\n<h2 id=\"support-for-external-helpers-library-tslib\" style=\"position:relative;\"><a href=\"#support-for-external-helpers-library-tslib\" aria-label=\"support for external helpers library tslib 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 external helpers library (<code>tslib</code>)</h2>\n<p>TypeScript injects a handful of helper functions such as <code>__extends</code> for inheritance, <code>__assign</code> for spread operator in object literals and JSX elements, and <code>__awaiter</code> for async functions.</p>\n<p>Previously there were two options:</p>\n<ol>\n<li>inject helpers in <em>every</em> file that needs them, or</li>\n<li>no helpers at all with <code>--noEmitHelpers</code>.</li>\n</ol>\n<p>The two options left more to be desired;\nbundling the helpers in every file was a pain point for customers trying to keep their package size small.\nAnd not including helpers, meant customers had to maintain their own helpers library.</p>\n<p>TypeScript 2.1 allows for including these files in your project once in a separate module, and the compiler will emit imports to them as needed.</p>\n<p>First, install the <a href=\"https://github.com/Microsoft/tslib\"><code>tslib</code></a> utility library:</p>\n<pre class=\"shiki\"><div class=\"language-id\">sh</div><div class='code-container'><code><span style=\"color: #000000\">npm install tslib</span></code></div></pre>\n<p>Second, compile your files using <code>--importHelpers</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">sh</div><div class='code-container'><code><span style=\"color: #000000\">tsc --module commonjs --importHelpers a.ts</span></code></div></pre>\n<p>So given the following input, the resulting <code>.js</code> file will include an import to <code>tslib</code> and use the <code>__assign</code> helper from it instead of inlining it.</p>\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\"> o = { a: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, name: </span><span style=\"color: #A31515\">\"o\"</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> copy = { ...o };</span></code></div></pre>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #A31515\">\"use strict\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> tslib_1 = require(</span><span style=\"color: #A31515\">\"tslib\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">exports.o = { a: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, name: </span><span style=\"color: #A31515\">\"o\"</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #000000\">exports.copy = tslib_1.__assign({}, exports.o);</span></code></div></pre>\n<h2 id=\"untyped-imports\" style=\"position:relative;\"><a href=\"#untyped-imports\" aria-label=\"untyped imports 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>Untyped imports</h2>\n<p>TypeScript has traditionally been overly strict about how you can import modules.\nThis was to avoid typos and prevent users from using modules incorrectly.</p>\n<p>However, a lot of the time, you might just want to import an existing module that may not have its own <code>.d.ts</code> file.\nPreviously this was an error.\nStarting with TypeScript 2.1 this is now much easier.</p>\n<p>With TypeScript 2.1, you can import a JavaScript module without needing a type declaration.\nA type declaration (such as <code>declare module \"foo\" { ... }</code> or <code>node_modules/@types/foo</code>) still takes priority if it exists.</p>\n<p>An import to a module with no declaration file will still be flagged as an error under <code>--noImplicitAny</code>.</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: #008000\">// Succeeds if `node_modules/asdf/index.js` exists</span>\n<span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { x } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"asdf\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h2 id=\"support-for---target-es2016---target-es2017-and---target-esnext\" style=\"position:relative;\"><a href=\"#support-for---target-es2016---target-es2017-and---target-esnext\" aria-label=\"support for   target es2016   target es2017 and   target esnext 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 <code>--target ES2016</code>, <code>--target ES2017</code> and <code>--target ESNext</code></h2>\n<p>TypeScript 2.1 supports three new target values <code>--target ES2016</code>, <code>--target ES2017</code> and <code>--target ESNext</code>.</p>\n<p>Using target <code>--target ES2016</code> will instruct the compiler not to transform ES2016-specific features, e.g. <code>**</code> operator.</p>\n<p>Similarly, <code>--target ES2017</code> will instruct the compiler not to transform ES2017-specific features like <code>async</code>/<code>await</code>.</p>\n<p><code>--target ESNext</code> targets latest supported <a href=\"https://github.com/tc39/proposals\">ES proposed features</a>.</p>\n<h2 id=\"improved-any-inference\" style=\"position:relative;\"><a href=\"#improved-any-inference\" aria-label=\"improved any inference permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Improved <code>any</code> Inference</h2>\n<p>Previously, if TypeScript couldn’t figure out the type of a variable, it would choose the <code>any</code> type.</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\"> x;      </span><span style=\"color: #008000\">// implicitly 'any'</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> y = []; </span><span style=\"color: #008000\">// implicitly 'any[]'</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> z: any; </span><span style=\"color: #008000\">// explicitly 'any'.</span></code></div></pre>\n<p>With TypeScript 2.1, instead of just choosing <code>any</code>, TypeScript will infer types based on what you end up assigning later on.</p>\n<p>This is only enabled if <code>--noImplicitAny</code> is set.</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\">let</span><span style=\"color: #000000\"> x;</span>\n\n<span style=\"color: #008000\">// You can still assign anything you want to 'x'.</span>\n<span style=\"color: #000000\">x = () </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> </span><span style=\"color: #09835A\">42</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #008000\">// After that last assignment, TypeScript 2.1 knows that 'x' has type '() =&gt; number'.</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> y = x();</span>\n\n<span style=\"color: #008000\">// Thanks to that, it will now tell you that you can't add a number to a function!</span>\n<span style=\"color: #000000\">console.log(x + y);</span>\n<span style=\"color: #008000\">//          ~~~~~</span>\n<span style=\"color: #008000\">// Error! Operator '+' cannot be applied to types '() =&gt; number' and 'number'.</span>\n\n<span style=\"color: #008000\">// TypeScript still allows you to assign anything you want to 'x'.</span>\n<span style=\"color: #000000\">x = </span><span style=\"color: #A31515\">\"Hello world!\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #008000\">// But now it also knows that 'x' is a 'string'!</span>\n<span style=\"color: #000000\">x.toLowerCase();</span></code></div></pre>\n<p>The same sort of tracking is now also done for empty arrays.</p>\n<p>A variable declared with no type annotation and an initial value of <code>[]</code> is considered an implicit <code>any[]</code> variable.\nHowever, each subsequent <code>x.push(value)</code>, <code>x.unshift(value)</code> or <code>x[n] = value</code> operation <em>evolves</em> the type of the variable in accordance with what elements are added to it.</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\"> f1() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x = [];</span>\n<span style=\"color: #000000\">    x.push(</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">    x[</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">] = </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    x.unshift(</span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> x;  </span><span style=\"color: #008000\">// (string | number | boolean)[]</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> f2() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</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\">if</span><span style=\"color: #000000\"> (cond()) {</span>\n<span style=\"color: #000000\">        x = [];</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">while</span><span style=\"color: #000000\"> (cond()) {</span>\n<span style=\"color: #000000\">            x.push(</span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">);</span>\n<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\"> x;  </span><span style=\"color: #008000\">// string[] | null</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"implicit-any-errors\" style=\"position:relative;\"><a href=\"#implicit-any-errors\" aria-label=\"implicit any errors 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 any errors</h2>\n<p>One great benefit of this is that you’ll see <em>way fewer</em> implicit <code>any</code> errors when running with <code>--noImplicitAny</code>.\nImplicit <code>any</code> errors are only reported when the compiler is unable to know the type of a variable without a type annotation.</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\">function</span><span style=\"color: #000000\"> f3() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x = [];  </span><span style=\"color: #008000\">// Error: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined.</span>\n<span style=\"color: #000000\">    x.push(</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> g() {</span>\n<span style=\"color: #000000\">        x;    </span><span style=\"color: #008000\">// Error: Variable 'x' implicitly has an 'any[]' type.</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"better-inference-for-literal-types\" style=\"position:relative;\"><a href=\"#better-inference-for-literal-types\" aria-label=\"better inference for literal 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>Better inference for literal types</h2>\n<p>String, numeric and boolean literal types (e.g. <code>\"abc\"</code>, <code>1</code>, and <code>true</code>) were previously inferred only in the presence of an explicit type annotation.\nStarting with TypeScript 2.1, literal types are <em>always</em> inferred for <code>const</code> variables and <code>readonly</code> properties.</p>\n<p>The type inferred for a <code>const</code> variable or <code>readonly</code> property without a type annotation is the type of the literal initializer.\nThe type inferred for a <code>let</code> variable, <code>var</code> variable, parameter, or non-<code>readonly</code> property with an initializer and no type annotation is the widened literal type of the initializer.\nWhere the widened type for a string literal type is <code>string</code>, <code>number</code> for numeric literal types, <code>boolean</code> for <code>true</code> or <code>false</code> and the containing enum for enum literal types.</p>\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\">const</span><span style=\"color: #000000\"> c1 = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type 1</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> c2 = c1;  </span><span style=\"color: #008000\">// Type 1</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> c3 = </span><span style=\"color: #A31515\">\"abc\"</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type \"abc\"</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> c4 = </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type true</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> c5 = cond ? </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> : </span><span style=\"color: #A31515\">\"abc\"</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type 1 | \"abc\"</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v1 = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type number</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v2 = c2;  </span><span style=\"color: #008000\">// Type number</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v3 = c3;  </span><span style=\"color: #008000\">// Type string</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v4 = c4;  </span><span style=\"color: #008000\">// Type boolean</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v5 = c5;  </span><span style=\"color: #008000\">// Type number | string</span></code></div></pre>\n<p>Literal type widening can be controlled through explicit type annotations.\nSpecifically, when an expression of a literal type is inferred for a const location without a type annotation, that <code>const</code> variable gets a widening literal type inferred.\nBut when a <code>const</code> location has an explicit literal type annotation, the <code>const</code> variable gets a non-widening literal type.</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\">const</span><span style=\"color: #000000\"> c1 = </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Widening type \"hello\"</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v1 = c1;  </span><span style=\"color: #008000\">// Type string</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> c2: </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\"> = </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">;  </span><span style=\"color: #008000\">// Type \"hello\"</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> v2 = c2;  </span><span style=\"color: #008000\">// Type \"hello\"</span></code></div></pre>\n<h2 id=\"use-returned-values-from-super-calls-as-this\" style=\"position:relative;\"><a href=\"#use-returned-values-from-super-calls-as-this\" aria-label=\"use returned values from super calls as this 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>Use returned values from super calls as ‘this’</h2>\n<p>In ES2015, constructors which return an object implicitly substitute the value of <code>this</code> for any callers of <code>super()</code>.\nAs a result, it is necessary to capture any potential return value of <code>super()</code> and replace it with <code>this</code>.\nThis change enables working with <a href=\"https://w3c.github.io/webcomponents/spec/custom/#htmlelement-constructor\">Custom Elements</a>, which takes advantage of this to initialize browser-allocated elements with user-written constructors.</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\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Base {</span>\n<span style=\"color: #000000\">    x: number;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #008000\">// return a new object other than `this`</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">            x: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        };</span>\n<span style=\"color: #000000\">    }</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\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">super</span><span style=\"color: #000000\">();</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.x = </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>Generates:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> Derived = (</span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> (_super) {</span>\n<span style=\"color: #000000\">    __extends(Derived, _super);</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> Derived() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> _this = _super.call(</span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">) || </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">        _this.x = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> _this;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> Derived;</span>\n<span style=\"color: #000000\">}(Base));</span></code></div></pre>\n<blockquote>\n<p>This change entails a break in the behavior of extending built-in classes like <code>Error</code>, <code>Array</code>, <code>Map</code>, etc.. Please see the <a href=\"https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\">extending built-ins breaking change documentation</a> for more details.</p>\n</blockquote>\n<h2 id=\"configuration-inheritance\" style=\"position:relative;\"><a href=\"#configuration-inheritance\" aria-label=\"configuration inheritance 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>Configuration inheritance</h2>\n<p>Often a project has multiple output targets, e.g. <code>ES5</code> and <code>ES2015</code>, debug and production or <code>CommonJS</code> and <code>System</code>;\nJust a few configuration options change between these two targets, and maintaining multiple <code>tsconfig.json</code> files can be a hassle.</p>\n<p>TypeScript 2.1 supports inheriting configuration using <code>extends</code>, where:</p>\n<ul>\n<li><code>extends</code> is a new top-level property in <code>tsconfig.json</code> (alongside <code>compilerOptions</code>, <code>files</code>, <code>include</code>, and <code>exclude</code>).</li>\n<li>The value of <code>extends</code> must be a string containing a path to another configuration file to inherit from.</li>\n<li>The configuration from the base file are loaded first, then overridden by those in the inheriting config file.</li>\n<li>Circularity between configuration files is not allowed.</li>\n<li><code>files</code>, <code>include</code> and <code>exclude</code> from the inheriting config file <em>overwrite</em> those from the base config file.</li>\n<li>All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.</li>\n</ul>\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<p><code>configs/base.json</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\">\"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\">\"strictNullChecks\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><code>tsconfig.json</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\">\"extends\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./configs/base\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0451A5\">\"files\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #A31515\">\"main.ts\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #A31515\">\"supplemental.ts\"</span>\n<span style=\"color: #000000\">  ]</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><code>tsconfig.nostrictnull.json</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\">\"extends\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./tsconfig\"</span><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\">\"strictNullChecks\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">false</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"new---alwaysstrict\" style=\"position:relative;\"><a href=\"#new---alwaysstrict\" aria-label=\"new   alwaysstrict 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>--alwaysStrict</code></h2>\n<p>Invoking the compiler with <code>--alwaysStrict</code> causes:</p>\n<ol>\n<li>Parses all the code in strict mode.</li>\n<li>Writes <code>\"use strict\";</code> directive atop every generated file.</li>\n</ol>\n<p>Modules are parsed automatically in strict mode.\nThe new flag is recommended for non-module code.</p>","headings":[{"value":"keyof and Lookup Types","depth":2},{"value":"Example","depth":5},{"value":"Example","depth":5},{"value":"Mapped Types","depth":2},{"value":"Partial, Readonly, Record, and Pick","depth":2},{"value":"Object Spread and Rest","depth":2},{"value":"Downlevel Async Functions","depth":2},{"value":"Example","depth":5},{"value":"tsconfig.json","depth":5},{"value":"dramaticWelcome.ts","depth":5},{"value":"Support for external helpers library (tslib)","depth":2},{"value":"Untyped imports","depth":2},{"value":"Example","depth":5},{"value":"Support for --target ES2016, --target ES2017 and --target ESNext","depth":2},{"value":"Improved any Inference","depth":2},{"value":"Example","depth":5},{"value":"Implicit any errors","depth":2},{"value":"Example","depth":5},{"value":"Better inference for literal types","depth":2},{"value":"Example","depth":5},{"value":"Example","depth":5},{"value":"Use returned values from super calls as ‘this’","depth":2},{"value":"Example","depth":5},{"value":"Configuration inheritance","depth":2},{"value":"Example","depth":5},{"value":"New --alwaysStrict","depth":2}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-2-1.html","title":"TypeScript 2.1"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-2-1.html","isOldHandbook":true}}}