{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-3-8.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":"4eb02299-58a3-5de4-bfc9-b709a46a829f","excerpt":"Type-Only Imports and Export This feature is something most users may never have to think about; however, if you’ve hit issues under --isolatedModules…","html":"<h2 id=\"type-only-imports-and-export\" style=\"position:relative;\"><a href=\"#type-only-imports-and-export\" aria-label=\"type only imports and export 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-Only Imports and Export</h2>\n<p>This feature is something most users may never have to think about; however, if you’ve hit issues under <code>--isolatedModules</code>, TypeScript’s <code>transpileModule</code> API, or Babel, this feature might be relevant.</p>\n<p>TypeScript 3.8 adds a new syntax for type-only imports and exports.</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\"> type { SomeThing } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"./some-module.js\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> type { SomeThing };</span></code></div></pre>\n<p><code>import type</code> only imports declarations to be used for type annotations and declarations.\nIt <em>always</em> gets fully erased, so there’s no remnant of it at runtime.\nSimilarly, <code>export type</code> only provides an export that can be used for type contexts, and is also erased from TypeScript’s output.</p>\n<p>It’s important to note that classes have a value at runtime and a type at design-time, and the use is context-sensitive.\nWhen using <code>import type</code> to import a class, you can’t do things like extend from it.</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\"> type { Component } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"react\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> ButtonProps {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// ...</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Button </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Component&lt;ButtonProps&gt; {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">//               ~~~~~~~~~</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// error! 'Component' only refers to a type, but is being used as a value here.</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// ...</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>If you’ve used Flow before, the syntax is fairly similar.\nOne difference is that we’ve added a few restrictions to avoid code that might appear ambiguous.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Is only 'Foo' a type? Or every declaration in the import?</span>\n<span style=\"color: #008000\">// We just give an error because it's not clear.</span>\n\n<span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> type Foo, { Bar, Baz } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"some-module\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #008000\">//     ~~~~~~~~~~~~~~~~~~~~~~</span>\n<span style=\"color: #008000\">// error! A type-only import can specify a default import or named bindings, but not both.</span></code></div></pre>\n<p>In conjunction with <code>import type</code>, TypeScript 3.8 also adds a new compiler flag to control what happens with imports that won’t be utilized at runtime: <code>importsNotUsedAsValues</code>.\nThis flag takes 3 different values:</p>\n<ul>\n<li><code>remove</code>: this is today’s behavior of dropping these imports. It’s going to continue to be the default, and is a non-breaking change.</li>\n<li><code>preserve</code>: this <em>preserves</em> all imports whose values are never used. This can cause imports/side-effects to be preserved.</li>\n<li><code>error</code>: this preserves all imports (the same as the <code>preserve</code> option), but will error when a value import is only used as a type. This might be useful if you want to ensure no values are being accidentally imported, but still make side-effect imports explicit.</li>\n</ul>\n<p>For more information about the feature, you can <a href=\"https://github.com/microsoft/TypeScript/pull/35200\">take a look at the pull request</a>, and <a href=\"https://github.com/microsoft/TypeScript/pull/36092/\">relevant changes</a> around broadening where imports from an <code>import type</code> declaration can be used.</p>\n<h2 id=\"ecmascript-private-fields\" style=\"position:relative;\"><a href=\"#ecmascript-private-fields\" aria-label=\"ecmascript private fields 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>ECMAScript Private Fields</h2>\n<p>TypeScript 3.8 brings support for ECMAScript’s private fields, part of the <a href=\"https://github.com/tc39/proposal-class-fields/\">stage-3 class fields proposal</a>.</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\"> Person {</span>\n<span style=\"color: #000000\">    #name: string</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">(name: string) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#name = name;</span>\n<span style=\"color: #000000\">    }</span>\n\n<span style=\"color: #000000\">    greet() {</span>\n<span style=\"color: #000000\">        console.log(</span><span style=\"color: #A31515\">`Hello, my name is </span><span style=\"color: #0000FF\">${this</span><span style=\"color: #A31515\">.#name</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\">!`</span><span style=\"color: #000000\">);</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\"> jeremy = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Person(</span><span style=\"color: #A31515\">\"Jeremy Bearimy\"</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #000000\">jeremy.#name</span>\n<span style=\"color: #008000\">//     ~~~~~</span>\n<span style=\"color: #008000\">// Property '#name' is not accessible outside class 'Person'</span>\n<span style=\"color: #008000\">// because it has a private identifier.</span></code></div></pre>\n<p>Unlike regular properties (even ones declared with the <code>private</code> modifier), private fields have a few rules to keep in mind.\nSome of them are:</p>\n<ul>\n<li>Private fields start with a <code>#</code> character. Sometimes we call these <em>private names</em>.</li>\n<li>Every private field name is uniquely scoped to its containing class.</li>\n<li>TypeScript accessibility modifiers like <code>public</code> or <code>private</code> can’t be used on private fields.</li>\n<li>Private fields can’t be accessed or even detected outside of the containing class - even by JS users! Sometimes we call this <em>hard privacy</em>.</li>\n</ul>\n<p>Apart from “hard” privacy, another benefit of private fields is that uniqueness we just mentioned.\nFor example, regular property declarations are prone to being overwritten in subclasses.</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\"> C {</span>\n<span style=\"color: #000000\">  foo = </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #000000\">  cHelper() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.foo;</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\"> D </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">  foo = </span><span style=\"color: #09835A\">20</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #000000\">  dHelper() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.foo;</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\"> instance = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> D();</span>\n<span style=\"color: #008000\">// 'this.foo' refers to the same property on each instance.</span>\n<span style=\"color: #000000\">console.log(instance.cHelper()); </span><span style=\"color: #008000\">// prints '20'</span>\n<span style=\"color: #000000\">console.log(instance.dHelper()); </span><span style=\"color: #008000\">// prints '20'</span></code></div></pre>\n<p>With private fields, you’ll never have to worry about this, since each field name is unique to the containing class.</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\"> C {</span>\n<span style=\"color: #000000\">    #foo = </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #000000\">    cHelper() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#foo;</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\"> D </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">    #foo = </span><span style=\"color: #09835A\">20</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #000000\">    dHelper() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#foo;</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\"> instance = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> D();</span>\n<span style=\"color: #008000\">// 'this.#foo' refers to a different field within each class.</span>\n<span style=\"color: #000000\">console.log(instance.cHelper()); </span><span style=\"color: #008000\">// prints '10'</span>\n<span style=\"color: #000000\">console.log(instance.dHelper()); </span><span style=\"color: #008000\">// prints '20'</span></code></div></pre>\n<p>Another thing worth noting is that accessing a private field on any other type will result in a <code>TypeError</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\"> Square {</span>\n<span style=\"color: #000000\">    #sideLength: number;</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">(sideLength: number) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#sideLength = sideLength;</span>\n<span style=\"color: #000000\">    }</span>\n\n<span style=\"color: #000000\">    equals(other: any) {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#sideLength === other.#sideLength;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> a = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Square(</span><span style=\"color: #09835A\">100</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> b = { sideLength: </span><span style=\"color: #09835A\">100</span><span style=\"color: #000000\"> };</span>\n\n<span style=\"color: #008000\">// Boom!</span>\n<span style=\"color: #008000\">// TypeError: attempted to get private field on non-instance</span>\n<span style=\"color: #008000\">// This fails because 'b' is not an instance of 'Square'.</span>\n<span style=\"color: #000000\">console.log(a.equals(b));</span></code></div></pre>\n<p>Finally, for any plain <code>.js</code> file users, private fields <em>always</em> have to be declared before they’re assigned to.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// No declaration for '#foo'</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// :(</span>\n\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">(foo: number) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// SyntaxError!</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// '#foo' needs to be declared before writing to it.</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#foo = foo;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>JavaScript has always allowed users to access undeclared properties, whereas TypeScript has always required declarations for class properties.\nWith private fields, declarations are always needed regardless of whether we’re working in <code>.js</code> or <code>.ts</code> files.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number} */</span>\n<span style=\"color: #000000\">  #foo;</span>\n\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">(foo: number) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// This works.</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.#foo = foo;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>For more information about the implementation, you can <a href=\"https://github.com/Microsoft/TypeScript/pull/30829\">check out the original pull request</a></p>\n<h3 id=\"which-should-i-use\" style=\"position:relative;\"><a href=\"#which-should-i-use\" aria-label=\"which should i use 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>Which should I use?</h3>\n<p>We’ve already received many questions on which type of privates you should use as a TypeScript user: most commonly, “should I use the <code>private</code> keyword, or ECMAScript’s hash/pound (<code>#</code>) private fields?”\nIt depends!</p>\n<p>When it comes to properties, TypeScript’s <code>private</code> modifiers are fully erased - that means that at runtime, it acts entirely like a normal property and there’s no way to tell that it was declared with a <code>private modifier. When using the</code>private` keyword, privacy is only enforced at compile-time/design-time, and for JavaScript consumers it’s entirely intent-based.</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\"> C {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">private</span><span style=\"color: #000000\"> foo = </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// This is an error at compile time,</span>\n<span style=\"color: #008000\">// but when TypeScript outputs .js files,</span>\n<span style=\"color: #008000\">// it'll run fine and print '10'.</span>\n<span style=\"color: #000000\">console.log(</span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> C().foo); </span><span style=\"color: #008000\">// prints '10'</span>\n<span style=\"color: #008000\">//                  ~~~</span>\n<span style=\"color: #008000\">// error! Property 'foo' is private and only accessible within class 'C'.</span>\n\n<span style=\"color: #008000\">// TypeScript allows this at compile-time</span>\n<span style=\"color: #008000\">// as a \"work-around\" to avoid the error.</span>\n<span style=\"color: #000000\">console.log(</span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> C()[</span><span style=\"color: #A31515\">\"foo\"</span><span style=\"color: #000000\">]); </span><span style=\"color: #008000\">// prints '10'</span></code></div></pre>\n<p>The upside is that this sort of “soft privacy” can help your consumers temporarily work around not having access to some API, and also works in any runtime.</p>\n<p>On the other hand, ECMAScript’s <code>#</code> privates are completely inaccessible outside of the class.</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\"> C {</span>\n<span style=\"color: #000000\">    #foo = </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">console.log(</span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> C().#foo); </span><span style=\"color: #008000\">// SyntaxError</span>\n<span style=\"color: #008000\">//                  ~~~~</span>\n<span style=\"color: #008000\">// TypeScript reports an error *and*</span>\n<span style=\"color: #008000\">// this won't work at runtime!</span>\n\n<span style=\"color: #000000\">console.log(</span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> C()[</span><span style=\"color: #A31515\">\"#foo\"</span><span style=\"color: #000000\">]); </span><span style=\"color: #008000\">// prints undefined</span>\n<span style=\"color: #008000\">//          ~~~~~~~~~~~~~~~</span>\n<span style=\"color: #008000\">// TypeScript reports an error under 'noImplicitAny',</span>\n<span style=\"color: #008000\">// and this prints 'undefined'.</span></code></div></pre>\n<p>This hard privacy is really useful for strictly ensuring that nobody can take use of any of your internals.\nIf you’re a library author, removing or renaming a private field should never cause a breaking change.</p>\n<p>As we mentioned, another benefit is that subclassing can be easier with ECMAScript’s <code>#</code> privates because they <em>really</em> are private.\nWhen using ECMAScript <code>#</code> private fields, no subclass ever has to worry about collisions in field naming.\nWhen it comes to TypeScript’s <code>private</code> property declarations, users still have to be careful not to trample over properties declared in superclasses.</p>\n<p>One more thing to think about is where you intend for your code to run.\nTypeScript currently can’t support this feature unless targeting ECMAScript 2015 (ES6) targets or higher.\nThis is because our downleveled implementation uses <code>WeakMap</code>s to enforce privacy, and <code>WeakMap</code>s can’t be polyfilled in a way that doesn’t cause memory leaks.\nIn contrast, TypeScript’s <code>private</code>-declared properties work with all targets - even ECMAScript 3!</p>\n<p>A final consideration might be speed: <code>private</code> properties are no different from any other property, so accessing them is as fast as any other property access no matter which runtime you target.\nIn contrast, because <code>#</code> private fields are downleveled using <code>WeakMap</code>s, they may be slower to use.\nWhile some runtimes might optimize their actual implementations of <code>#</code> private fields, and even have speedy <code>WeakMap</code> implementations, that might not be the case in all runtimes.</p>\n<h2 id=\"span-idexport-star-as-namespace-syntax--export--as-ns-syntax\" style=\"position:relative;\"><a href=\"#span-idexport-star-as-namespace-syntax--export--as-ns-syntax\" aria-label=\"span idexport star as namespace syntax  export  as ns syntax 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><span id=\"export-star-as-namespace-syntax\" /> <code>export * as ns</code> Syntax</h2>\n<p>It’s often common to have a single entry-point that exposes all the members of another module as a single member.</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\"> </span><span style=\"color: #0000FF\">*</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> utilities </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"./utilities.js\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> { utilities };</span></code></div></pre>\n<p>This is so common that ECMAScript 2020 recently added a new syntax to support this pattern!</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\">*</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> utilities </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"./utilities.js\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>This is a nice quality-of-life improvement to JavaScript, and TypeScript 3.8 implements this syntax.\nWhen your module target is earlier than <code>es2020</code>, TypeScript will output something along the lines of the first code snippet.</p>\n<h2 id=\"span-idtop-level-await--top-level-await\" style=\"position:relative;\"><a href=\"#span-idtop-level-await--top-level-await\" aria-label=\"span idtop level await  top level await 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><span id=\"top-level-await\" /> Top-Level <code>await</code></h2>\n<p>TypeScript 3.8 provides support for a handy upcoming ECMAScript feature called “top-level <code>await</code>“.</p>\n<p>JavaScript users often introduce an <code>async</code> function in order to use <code>await</code>, and then immediately called the function after defining it.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">async</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> main() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> response = </span><span style=\"color: #0000FF\">await</span><span style=\"color: #000000\"> fetch(</span><span style=\"color: #A31515\">\"...\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> greeting = </span><span style=\"color: #0000FF\">await</span><span style=\"color: #000000\"> response.text();</span>\n<span style=\"color: #000000\">  console.log(greeting);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">main().catch(e </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> console.error(e));</span></code></div></pre>\n<p>This is because previously in JavaScript (along with most other languages with a similar feature), <code>await</code> was only allowed within the body of an <code>async</code> function.\nHowever, with top-level <code>await</code>, we can use <code>await</code> at the top level of a module.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> response = </span><span style=\"color: #0000FF\">await</span><span style=\"color: #000000\"> fetch(</span><span style=\"color: #A31515\">\"...\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> greeting = </span><span style=\"color: #0000FF\">await</span><span style=\"color: #000000\"> response.text();</span>\n<span style=\"color: #000000\">console.log(greeting);</span>\n\n<span style=\"color: #008000\">// Make sure we're a module</span>\n<span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> {};</span></code></div></pre>\n<p>Note there’s a subtlety: top-level <code>await</code> only works at the top level of a <em>module</em>, and files are only considered modules when TypeScript finds an <code>import</code> or an <code>export</code>.\nIn some basic cases, you might need to write out <code>export {}</code> as some boilerplate to make sure of this.</p>\n<p>Top level <code>await</code> may not work in all environments where you might expect at this point.\nCurrently, you can only use top level <code>await</code> when the <code>target</code> compiler option is <code>es2017</code> or above, and <code>module</code> is <code>esnext</code> or <code>system</code>.\nSupport within several environments and bundlers may be limited or may require enabling experimental support.</p>\n<p>For more information on our implementation, you can <a href=\"https://github.com/microsoft/TypeScript/pull/35813\">check out the original pull request</a>.</p>\n<h2 id=\"es2020-for-target-and-module\" style=\"position:relative;\"><a href=\"#es2020-for-target-and-module\" aria-label=\"es2020 for target and module 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>es2020</code> for <code>target</code> and <code>module</code></h2>\n<p>TypeScript 3.8 supports <code>es2020</code> as an option for <code>module</code> and <code>target</code>.\nThis will preserve newer ECMAScript 2020 features like optional chaining, nullish coalescing, <code>export * as ns</code>, and dynamic <code>import(...)</code> syntax.\nIt also means <code>bigint</code> literals now have a stable <code>target</code> below <code>esnext</code>.</p>\n<h2 id=\"jsdoc-property-modifiers\" style=\"position:relative;\"><a href=\"#jsdoc-property-modifiers\" aria-label=\"jsdoc property modifiers 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>JSDoc Property Modifiers</h2>\n<p>TypeScript 3.8 supports JavaScript files by turning on the <code>allowJs</code> flag, and also supports <em>type-checking</em> those JavaScript files via the <code>checkJs</code> option or by adding a <code>// @ts-check</code> comment to the top of your <code>.js</code> files.</p>\n<p>Because JavaScript files don’t have dedicated syntax for type-checking, TypeScript leverages JSDoc.\nTypeScript 3.8 understands a few new JSDoc tags for properties.</p>\n<p>First are the accessibility modifiers: <code>@public</code>, <code>@private</code>, and <code>@protected</code>.\nThese tags work exactly like <code>public</code>, <code>private</code>, and <code>protected</code> respectively work in TypeScript.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">// @ts-check</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Foo {</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\">/** </span><span style=\"color: #0000FF\">@private</span><span style=\"color: #008000\"> */</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.stuff = </span><span style=\"color: #09835A\">100</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n\n<span style=\"color: #000000\">  printStuff() {</span>\n<span style=\"color: #000000\">    console.log(</span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.stuff);</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Foo().stuff;</span>\n<span style=\"color: #008000\">//        ~~~~~</span>\n<span style=\"color: #008000\">// error! Property 'stuff' is private and only accessible within class 'Foo'.</span></code></div></pre>\n<ul>\n<li><code>@public</code> is always implied and can be left off, but means that a property can be reached from anywhere.</li>\n<li><code>@private</code> means that a property can only be used within the containing class.</li>\n<li><code>@protected</code> means that a property can only be used within the containing class, and all derived subclasses, but not on dissimilar instances of the containing class.</li>\n</ul>\n<p>Next, we’ve also added the <code>@readonly</code> modifier to ensure that a property is only ever written to during initialization.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">// @ts-check</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Foo {</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\">/** </span><span style=\"color: #0000FF\">@readonly</span><span style=\"color: #008000\"> */</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.stuff = </span><span style=\"color: #09835A\">100</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n\n<span style=\"color: #000000\">  writeToStuff() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.stuff = </span><span style=\"color: #09835A\">200</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">//   ~~~~~</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// Cannot assign to 'stuff' because it is a read-only property.</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Foo().stuff++;</span>\n<span style=\"color: #008000\">//        ~~~~~</span>\n<span style=\"color: #008000\">// Cannot assign to 'stuff' because it is a read-only property.</span></code></div></pre>\n<h2 id=\"better-directory-watching-on-linux-and-watchoptions\" style=\"position:relative;\"><a href=\"#better-directory-watching-on-linux-and-watchoptions\" aria-label=\"better directory watching on linux and watchoptions 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 Directory Watching on Linux and <code>watchOptions</code></h2>\n<p>TypeScript 3.8 ships a new strategy for watching directories, which is crucial for efficiently picking up changes to <code>node_modules</code>.</p>\n<p>For some context, on operating systems like Linux, TypeScript installs directory watchers (as opposed to file watchers) on <code>node_modules</code> and many of its subdirectories to detect changes in dependencies.\nThis is because the number of available file watchers is often eclipsed by the of files in <code>node_modules</code>, whereas there are way fewer directories to track.</p>\n<p>Older versions of TypeScript would <em>immediately</em> install directory watchers on folders, and at startup that would be fine; however, during an npm install, a lot of activity will take place within <code>node_modules</code> and that can overwhelm TypeScript, often slowing editor sessions to a crawl.\nTo prevent this, TypeScript 3.8 waits slightly before installing directory watchers to give these highly volatile directories some time to stabilize.</p>\n<p>Because every project might work better under different strategies, and this new approach might not work well for your workflows, TypeScript 3.8 introduces a new <code>watchOptions</code> field in <code>tsconfig.json</code> and <code>jsconfig.json</code> which allows users to tell the compiler/language service which watching strategies should be used to keep track of files and directories.</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: #008000\">// Some typical compiler options</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #CD3131\">compilerOptions</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #CD3131\">target</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"es2020\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #CD3131\">moduleResolution</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"node\"</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// ...</span>\n<span style=\"color: #000000\">  },</span>\n\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// NEW: Options for file/directory watching</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #CD3131\">watchOptions</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// Use native file system events for files and directories</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #CD3131\">watchFile</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"useFsEvents\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #CD3131\">watchDirectory</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"useFsEvents\"</span><span style=\"color: #000000\">,</span>\n\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// Poll files for updates more frequently</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// when they're updated a lot.</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #CD3131\">fallbackPolling</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"dynamicPriority\"</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><code>watchOptions</code> contains 4 new options that can be configured:</p>\n<ul>\n<li>\n<p><code>watchFile</code>: the strategy for how individual files are watched. This can be set to</p>\n<ul>\n<li><code>fixedPollingInterval</code>: Check every file for changes several times a second at a fixed interval.</li>\n<li><code>priorityPollingInterval</code>: Check every file for changes several times a second, but use heuristics to check certain types of files less frequently than others.</li>\n<li><code>dynamicPriorityPolling</code>: Use a dynamic queue where less-frequently modified files will be checked less often.</li>\n<li><code>useFsEvents</code> (the default): Attempt to use the operating system/file system’s native events for file changes.</li>\n<li><code>useFsEventsOnParentDirectory</code>: Attempt to use the operating system/file system’s native events to listen for changes on a file’s containing directories. This can use fewer file watchers, but might be less accurate.</li>\n</ul>\n</li>\n<li>\n<p><code>watchDirectory</code>: the strategy for how entire directory trees are watched under systems that lack recursive file-watching functionality. This can be set to:</p>\n<ul>\n<li><code>fixedPollingInterval</code>: Check every directory for changes several times a second at a fixed interval.</li>\n<li><code>dynamicPriorityPolling</code>: Use a dynamic queue where less-frequently modified directories will be checked less often.</li>\n<li><code>useFsEvents</code> (the default): Attempt to use the operating system/file system’s native events for directory changes.</li>\n</ul>\n</li>\n<li>\n<p><code>fallbackPolling</code>: when using file system events, this option specifies the polling strategy that gets used when the system runs out of native file watchers and/or doesn’t support native file watchers. This can be set to</p>\n<ul>\n<li><code>fixedPollingInterval</code>: <em>(See above.)</em></li>\n<li><code>priorityPollingInterval</code>: <em>(See above.)</em></li>\n<li><code>dynamicPriorityPolling</code>: <em>(See above.)</em></li>\n</ul>\n</li>\n<li><code>synchronousWatchDirectory</code>: Disable deferred watching on directories. Deferred watching is useful when lots of file changes might occur at once (e.g. a change in <code>node_modules</code> from running <code>npm install</code>), but you might want to disable it with this flag for some less-common setups.</li>\n</ul>\n<p>For more information on these changes, <a href=\"https://github.com/microsoft/TypeScript/pull/35615\">head over to GitHub to see the pull request</a> to read more.</p>\n<h2 id=\"fast-and-loose-incremental-checking\" style=\"position:relative;\"><a href=\"#fast-and-loose-incremental-checking\" aria-label=\"fast and loose incremental 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>“Fast and Loose” Incremental Checking</h2>\n<p>TypeScript 3.8 introduces a new compiler option called <code>assumeChangesOnlyAffectDirectDependencies</code>.\nWhen this option is enabled, TypeScript will avoid rechecking/rebuilding all truly possibly-affected files, and only recheck/rebuild files that have changed as well as files that directly import them.</p>\n<p>For example, consider a file <code>fileD.ts</code> that imports <code>fileC.ts</code> that imports <code>fileB.ts</code> that imports <code>fileA.ts</code> as follows:</p>\n<pre><code>fileA.ts &#x3C;- fileB.ts &#x3C;- fileC.ts &#x3C;- fileD.ts\n</code></pre>\n<p>In <code>--watch</code> mode, a change in <code>fileA.ts</code> would typically mean that TypeScript would need to at least re-check <code>fileB.ts</code>, <code>fileC.ts</code>, and <code>fileD.ts</code>.\nUnder <code>assumeChangesOnlyAffectDirectDependencies</code>, a change in <code>fileA.ts</code> means that only <code>fileA.ts</code> and <code>fileB.ts</code> need to be re-checked.</p>\n<p>In a codebase like Visual Studio Code, this reduced rebuild times for changes in certain files from about 14 seconds to about 1 second.\nWhile we don’t necessarily recommend this option for all codebases, you might be interested if you have an extremely large codebase and are willing to defer full project errors until later (e.g. a dedicated build via a <code>tsconfig.fullbuild.json</code> or in CI).</p>\n<p>For more details, you can <a href=\"https://github.com/microsoft/TypeScript/pull/35711\">see the original pull request</a>.</p>","headings":[{"value":"Type-Only Imports and Export","depth":2},{"value":"ECMAScript Private Fields","depth":2},{"value":"Which should I use?","depth":3},{"value":"<span id=\"export-star-as-namespace-syntax\" /> export * as ns Syntax","depth":2},{"value":"<span id=\"top-level-await\" /> Top-Level await","depth":2},{"value":"es2020 for target and module","depth":2},{"value":"JSDoc Property Modifiers","depth":2},{"value":"Better Directory Watching on Linux and watchOptions","depth":2},{"value":"“Fast and Loose” Incremental Checking","depth":2}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-3-8.html","title":"TypeScript 3.8"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-3-8.html","isOldHandbook":true}}}