{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/basic-types.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":"e25a9a61-0571-5742-a5aa-eac976706b36","excerpt":"Introduction For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and…","html":"<h1 id=\"introduction\" style=\"position:relative;\"><a href=\"#introduction\" aria-label=\"introduction 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>Introduction</h1>\n<p>For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and the like.\nIn TypeScript, we support much the same types as you would expect in JavaScript, with a convenient enumeration type thrown in to help things along.</p>\n<h1 id=\"boolean\" style=\"position:relative;\"><a href=\"#boolean\" aria-label=\"boolean 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>Boolean</h1>\n<p>The most basic datatype is the simple true/false value, which JavaScript and TypeScript call a <code>boolean</code> value.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>isDone:<span class='lsp-result'>let isDone: boolean</span></span> boolean = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h1 id=\"number\" style=\"position:relative;\"><a href=\"#number\" aria-label=\"number 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>Number</h1>\n<p>As in JavaScript, all numbers in TypeScript are floating point values.\nThese floating point numbers get the type <code>number</code>.\nIn addition to hexadecimal and decimal literals, TypeScript also supports binary and octal literals introduced in ECMAScript 2015.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>decimal:<span class='lsp-result'>let decimal: number</span></span> number = </span><span style=\"color: #09835A\">6</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>hex:<span class='lsp-result'>let hex: number</span></span> number = </span><span style=\"color: #09835A\">0xf00d</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>binary:<span class='lsp-result'>let binary: number</span></span> number = </span><span style=\"color: #09835A\">0b1010</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>octal:<span class='lsp-result'>let octal: number</span></span> number = </span><span style=\"color: #09835A\">0o744</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h1 id=\"string\" style=\"position:relative;\"><a href=\"#string\" aria-label=\"string 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>String</h1>\n<p>Another fundamental part of creating programs in JavaScript for webpages and servers alike is working with textual data.\nAs in other languages, we use the type <code>string</code> to refer to these textual datatypes.\nJust like JavaScript, TypeScript also uses double quotes (<code>\"</code>) or single quotes (<code>'</code>) to surround string data.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>color:<span class='lsp-result'>let color: string</span></span> string = </span><span style=\"color: #A31515\">\"blue\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\"><span class='lsp'>color <span class='lsp-result'>let color: string</span></span>= </span><span style=\"color: #A31515\">\"red\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>You can also use <em>template strings</em>, which can span multiple lines and have embedded expressions.\nThese strings are surrounded by the backtick/backquote (<code>`</code>) character, and embedded expressions are of the form <code>${ expr }</code>.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>fullName:<span class='lsp-result'>let fullName: string</span></span> string = </span><span style=\"color: #A31515\">`Bob Bobbington`</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>age:<span class='lsp-result'>let age: number</span></span> number = </span><span style=\"color: #09835A\">37</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>sentence:<span class='lsp-result'>let sentence: string</span></span> string = </span><span style=\"color: #A31515\">`Hello, my name is </span><span style=\"color: #0000FF\">${</span><span style=\"color: #A31515\"><span class='lsp'>fullName<span class='lsp-result'>let fullName: string</span></span></span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\">.</span>\n\n<span style=\"color: #A31515\">I'll be </span><span style=\"color: #0000FF\">${</span><span style=\"color: #A31515\"><span class='lsp'>age <span class='lsp-result'>let age: number</span></span></span><span style=\"color: #000000\">+</span><span style=\"color: #A31515\"> </span><span style=\"color: #09835A\">1</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\"> years old next month.`</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>This is equivalent to declaring <code>sentence</code> like so:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> sentence: string =</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\"Hello, my name is \"</span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  fullName +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\".\\n\\n\"</span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\"I'll be \"</span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  (age + </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">) +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\" years old next month.\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h1 id=\"array\" style=\"position:relative;\"><a href=\"#array\" aria-label=\"array 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>Array</h1>\n<p>TypeScript, like JavaScript, allows you to work with arrays of values.\nArray types can be written in one of two ways.\nIn the first, you use the type of the elements followed by <code>[]</code> to denote an array of that element type:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>list:<span class='lsp-result'>let list: number[]</span></span> number[] = [</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">];</span></code></div></pre>\n<p>The second way uses a generic array type, <code>Array&#x3C;elemType></code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>list:<span class='lsp-result'>let list: number[]</span></span> <span class='lsp'>Array&lt;<span class='lsp-result'>interface Array&lt;T&gt;</span></span>number&gt; = [</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">];</span></code></div></pre>\n<h1 id=\"tuple\" style=\"position:relative;\"><a href=\"#tuple\" aria-label=\"tuple 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>Tuple</h1>\n<p>Tuple types allow you to express an array with a fixed number of elements whose types are known, but need not be the same. For example, you may want to represent a value as a pair of a <code>string</code> and a <code>number</code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Declare a tuple type</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>x:<span class='lsp-result'>let x: [string, number]</span></span> [string, number];</span>\n<span style=\"color: #008000\">// Initialize it</span>\n<span style=\"color: #000000\"><span class='lsp'>x <span class='lsp-result'>let x: [string, number]</span></span>= [</span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #008000\">// Initialize it incorrectly</span>\n<span style=\"color: #000000\"><span class='lsp'>x <span class='lsp-result'>let x: [string, number]</span></span>= [</span><span style=\"color: #09835A\"><span class='err'>10</span></span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\"><span class='err'>&quot;hello&quot;</span></span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// Error</span>\n<span class=\"error\"><span>Type 'number' is not assignable to type 'string'.</br>Type 'string' is not assignable to type 'number'.</span><span class=\"code\">2322<br/>2322</span></span><span class=\"error-behind\">Type 'number' is not assignable to type 'string'.</br>Type 'string' is not assignable to type 'number'.</span></code></div></pre>\n<p>When accessing an element with a known index, the correct type is retrieved:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">console.log(x[</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">].substring(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">)); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">console.log(x[</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">].substring(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">)); </span><span style=\"color: #008000\">// Error, 'number' does not have 'substring'</span></code></div></pre>\n<p>Accessing an element outside the set of known indices fails with an error:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">x[</span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">] = </span><span style=\"color: #A31515\">\"world\"</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error, Property '3' does not exist on type '[string, number]'.</span>\n\n<span style=\"color: #000000\">console.log(x[</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">].toString()); </span><span style=\"color: #008000\">// Error, Property '5' does not exist on type '[string, number]'.</span></code></div></pre>\n<h1 id=\"enum\" style=\"position:relative;\"><a href=\"#enum\" aria-label=\"enum 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>Enum</h1>\n<p>A helpful addition to the standard set of datatypes from JavaScript is the <code>enum</code>.\nAs in languages like C#, an enum is a way of giving more friendly names to sets of numeric values.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Red,<span class='lsp-result'>(enum member) Color.Red = 0</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Green,<span class='lsp-result'>(enum member) Color.Green = 1</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Blue<span class='lsp-result'>(enum member) Color.Blue = 2</span></span></span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>c:<span class='lsp-result'>let c: Color</span></span> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span>= <span class='lsp'>Color.<span class='lsp-result'>enum Color</span></span><span class='lsp'>Green;<span class='lsp-result'>(enum member) Color.Green = 1</span></span></span></code></div></pre>\n<p>By default, enums begin numbering their members starting at <code>0</code>.\nYou can change this by manually setting the value of one of its members.\nFor example, we can start the previous example at <code>1</code> instead of <code>0</code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Red <span class='lsp-result'>(enum member) Color.Red = 1</span></span>= </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  <span class='lsp'>Green,<span class='lsp-result'>(enum member) Color.Green = 2</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Blue<span class='lsp-result'>(enum member) Color.Blue = 3</span></span></span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>c:<span class='lsp-result'>let c: Color</span></span> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span>= <span class='lsp'>Color.<span class='lsp-result'>enum Color</span></span><span class='lsp'>Green;<span class='lsp-result'>(enum member) Color.Green = 2</span></span></span></code></div></pre>\n<p>Or, even manually set all the values in the enum:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Red <span class='lsp-result'>(enum member) Color.Red = 1</span></span>= </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  <span class='lsp'>Green <span class='lsp-result'>(enum member) Color.Green = 2</span></span>= </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  <span class='lsp'>Blue <span class='lsp-result'>(enum member) Color.Blue = 4</span></span>= </span><span style=\"color: #09835A\">4</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>c:<span class='lsp-result'>let c: Color</span></span> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span>= <span class='lsp'>Color.<span class='lsp-result'>enum Color</span></span><span class='lsp'>Green;<span class='lsp-result'>(enum member) Color.Green = 2</span></span></span></code></div></pre>\n<p>A handy feature of enums is that you can also go from a numeric value to the name of that value in the enum.\nFor example, if we had the value <code>2</code> but weren’t sure what that mapped to in the <code>Color</code> enum above, we could look up the corresponding name:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <span class='lsp'>Color <span class='lsp-result'>enum Color</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Red <span class='lsp-result'>(enum member) Color.Red = 1</span></span>= </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  <span class='lsp'>Green,<span class='lsp-result'>(enum member) Color.Green = 2</span></span></span>\n<span style=\"color: #000000\">  <span class='lsp'>Blue<span class='lsp-result'>(enum member) Color.Blue = 3</span></span></span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>colorName:<span class='lsp-result'>let colorName: string</span></span> string = <span class='lsp'>Color[<span class='lsp-result'>enum Color</span></span></span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">];</span>\n\n<span style=\"color: #000000\"><span class='lsp'>console.<span class='lsp-result'>var console: Console</span></span><span class='lsp'>log(<span class='lsp-result'>(method) Console.log(message?: any, ...optionalParams: any[]): void</span></span><span class='lsp'>colorName)<span class='lsp-result'>let colorName: string</span></span>; </span><span style=\"color: #008000\">// Displays 'Green' as its value is 2 above</span></code></div></pre>\n<h1 id=\"any\" style=\"position:relative;\"><a href=\"#any\" aria-label=\"any 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>Any</h1>\n<p>We may need to describe the type of variables that we do not know when we are writing an application.\nThese values may come from dynamic content, e.g. from the user or a 3rd party library.\nIn these cases, we want to opt-out of type checking and let the values pass through compile-time checks.\nTo do so, we label these with the <code>any</code> type:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>notSure:<span class='lsp-result'>let notSure: any</span></span> any = </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\"><span class='lsp'>notSure <span class='lsp-result'>let notSure: any</span></span>= </span><span style=\"color: #A31515\">\"maybe a string instead\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\"><span class='lsp'>notSure <span class='lsp-result'>let notSure: any</span></span>= </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// okay, definitely a boolean</span></code></div></pre>\n<p>The <code>any</code> type is a powerful way to work with existing JavaScript, allowing you to gradually opt-in and opt-out of type checking during compilation.\nYou might expect <code>Object</code> to play a similar role, as it does in other languages.\nHowever, variables of type <code>Object</code> only allow you to assign any value to them. You can’t call arbitrary methods on them, even ones that actually exist:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>notSure:<span class='lsp-result'>let notSure: any</span></span> any = </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\"><span class='lsp'>notSure.<span class='lsp-result'>let notSure: any</span></span><span class='lsp'>ifItExists(<span class='lsp-result'>any</span></span>); </span><span style=\"color: #008000\">// okay, ifItExists might exist at runtime</span>\n<span style=\"color: #000000\"><span class='lsp'>notSure.<span class='lsp-result'>let notSure: any</span></span><span class='lsp'>toFixed(<span class='lsp-result'>any</span></span>); </span><span style=\"color: #008000\">// okay, toFixed exists (but the compiler doesn't check)</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>prettySure:<span class='lsp-result'>let prettySure: Object</span></span> <span class='lsp'>Object <span class='lsp-result'>interface Object</span></span>= </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\"><span class='lsp'>prettySure.<span class='lsp-result'>let prettySure: Object</span></span><span class='err lsp'>toFixed(<span class='lsp-result'>any</span></span>); </span><span style=\"color: #008000\">// Error: Property 'toFixed' doesn't exist on type 'Object'.</span>\n<span class=\"error\"><span>Property 'toFixed' does not exist on type 'Object'.</span><span class=\"code\">2339</span></span><span class=\"error-behind\">Property 'toFixed' does not exist on type 'Object'.</span></code></div></pre>\n<p>The <code>any</code> type is also handy if you know some part of the type, but perhaps not all of it.\nFor example, you may have an array but the array has a mix of different types:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>list:<span class='lsp-result'>let list: any[]</span></span> any[] = [</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"free\"</span><span style=\"color: #000000\">];</span>\n\n<span style=\"color: #000000\"><span class='lsp'>list[<span class='lsp-result'>let list: any[]</span></span></span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">] = </span><span style=\"color: #09835A\">100</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h1 id=\"void\" style=\"position:relative;\"><a href=\"#void\" aria-label=\"void 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>Void</h1>\n<p><code>void</code> is a little like the opposite of <code>any</code>: the absence of having any type at all.\nYou may commonly see this as the return type of functions that do not return a value:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <span class='lsp'>warnUser(<span class='lsp-result'>function warnUser(): void</span></span>): void {</span>\n<span style=\"color: #000000\">  <span class='lsp'>console.<span class='lsp-result'>var console: Console</span></span><span class='lsp'>log(<span class='lsp-result'>(method) Console.log(message?: any, ...optionalParams: any[]): void</span></span></span><span style=\"color: #A31515\">\"This is my warning message\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Declaring variables of type <code>void</code> is not useful because you can only assign <code>null</code> (only if <code>--strictNullChecks</code> is not specified, see next section) or <code>undefined</code> to them:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>unusable:<span class='lsp-result'>let unusable: void</span></span> void = </span><span style=\"color: #0000FF\"><span class='lsp'>undefined<span class='lsp-result'>var undefined</span></span></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\"><span class='lsp'>unusable <span class='lsp-result'>let unusable: void</span></span>= </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK if `--strictNullChecks` is not given</span></code></div></pre>\n<h1 id=\"null-and-undefined\" style=\"position:relative;\"><a href=\"#null-and-undefined\" aria-label=\"null and undefined permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Null and Undefined</h1>\n<p>In TypeScript, both <code>undefined</code> and <code>null</code> actually have their own types named <code>undefined</code> and <code>null</code> respectively.\nMuch like <code>void</code>, they’re not extremely useful on their own:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Not much else we can assign to these variables!</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>u:<span class='lsp-result'>let u: undefined</span></span> undefined = </span><span style=\"color: #0000FF\"><span class='lsp'>undefined<span class='lsp-result'>var undefined</span></span></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>n:<span class='lsp-result'>let n: null</span></span> null = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p>By default <code>null</code> and <code>undefined</code> are subtypes of all other types.\nThat means you can assign <code>null</code> and <code>undefined</code> to something like <code>number</code>.</p>\n<p>However, when using the <code>--strictNullChecks</code> flag, <code>null</code> and <code>undefined</code> are only assignable to <code>any</code> and their respective types (the one exception being that <code>undefined</code> is also assignable to <code>void</code>).\nThis helps avoid <em>many</em> common errors.\nIn cases where you want to pass in either a <code>string</code> or <code>null</code> or <code>undefined</code>, you can use the union type <code>string | null | undefined</code>.</p>\n<p>Union types are an advanced topic that we’ll cover in a later chapter.</p>\n<blockquote>\n<p>As a note: we encourage the use of <code>--strictNullChecks</code> when possible, but for the purposes of this handbook, we will assume it is turned off.</p>\n</blockquote>\n<h1 id=\"never\" style=\"position:relative;\"><a href=\"#never\" aria-label=\"never 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>Never</h1>\n<p>The <code>never</code> type represents the type of values that never occur.\nFor instance, <code>never</code> is the return type for a function expression or an arrow function expression that always throws an exception or one that never returns;\nVariables also acquire the type <code>never</code> when narrowed by any type guards that can never be true.</p>\n<p>The <code>never</code> type is a subtype of, and assignable to, every type; however, <em>no</em> type is a subtype of, or assignable to, <code>never</code> (except <code>never</code> itself).\nEven <code>any</code> isn’t assignable to <code>never</code>.</p>\n<p>Some examples of functions returning <code>never</code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Function returning never must have unreachable end point</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <span class='lsp'>error(<span class='lsp-result'>function error(message: string): never</span></span><span class='lsp'>message:<span class='lsp-result'>(parameter) message: string</span></span> string): never {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">throw</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> <span class='lsp'>Error(<span class='lsp-result'>var Error: ErrorConstructor&#13;new (message?: string | undefined) =&gt; Error</span></span><span class='lsp'>message)<span class='lsp-result'>(parameter) message: string</span></span></span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Inferred return type is never</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <span class='lsp'>fail(<span class='lsp-result'>function fail(): never</span></span>) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> <span class='lsp'>error(<span class='lsp-result'>function error(message: string): never</span></span></span><span style=\"color: #A31515\">\"Something failed\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Function returning never must have unreachable end point</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <span class='lsp'>infiniteLoop(<span class='lsp-result'>function infiniteLoop(): never</span></span>): never {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">while</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">) {}</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h1 id=\"object\" style=\"position:relative;\"><a href=\"#object\" aria-label=\"object 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</h1>\n<p><code>object</code> is a type that represents the non-primitive type, i.e. anything that is not <code>number</code>, <code>string</code>, <code>boolean</code>, <code>symbol</code>, <code>null</code>, or <code>undefined</code>.</p>\n<p>With <code>object</code> type, APIs like <code>Object.create</code> can be better represented. For example:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span><span class='lsp'>o:<span class='lsp-result'>(parameter) o: object | null</span></span> object | null): void;</span>\n\n<span style=\"color: #000000\"><span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span>{ <span class='lsp'>prop:<span class='lsp-result'>(property) prop: number</span></span></span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\"> }); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\"><span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span></span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK</span>\n\n<span style=\"color: #000000\"><span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span></span><span style=\"color: #09835A\"><span class='err'>42</span></span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error</span>\n<span class=\"error\"><span>Argument of type '42' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type '42' is not assignable to parameter of type 'object | null'.</span><span style=\"color: #000000\"><span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span></span><span style=\"color: #A31515\"><span class='err'>&quot;string&quot;</span></span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error</span>\n<span class=\"error\"><span>Argument of type '\"string\"' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type '\"string\"' is not assignable to parameter of type 'object | null'.</span><span style=\"color: #000000\"><span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span></span><span style=\"color: #0000FF\"><span class='err'>false</span></span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error</span>\n<span class=\"error\"><span>Argument of type 'false' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type 'false' is not assignable to parameter of type 'object | null'.</span><span style=\"color: #000000\"><span class='lsp'>create(<span class='lsp-result'>function create(o: object | null): void</span></span></span><span style=\"color: #0000FF\"><span class='err lsp'>undefined<span class='lsp-result'>var undefined</span></span></span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error</span>\n<span class=\"error\"><span>Argument of type 'undefined' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type 'undefined' is not assignable to parameter of type 'object | null'.</span></code></div></pre>\n<h1 id=\"type-assertions\" style=\"position:relative;\"><a href=\"#type-assertions\" aria-label=\"type assertions 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 assertions</h1>\n<p>Sometimes you’ll end up in a situation where you’ll know more about a value than TypeScript does.\nUsually this will happen when you know the type of some entity could be more specific than its current type.</p>\n<p><em>Type assertions</em> are a way to tell the compiler “trust me, I know what I’m doing.”\nA type assertion is like a type cast in other languages, but performs no special checking or restructuring of data.\nIt has no runtime impact, and is used purely by the compiler.\nTypeScript assumes that you, the programmer, have performed any special checks that you need.</p>\n<p>Type assertions have two forms.\nOne is the “angle-bracket” syntax:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>someValue:<span class='lsp-result'>let someValue: any</span></span> any = </span><span style=\"color: #A31515\">\"this is a string\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>strLength:<span class='lsp-result'>let strLength: number</span></span> number = (&lt;string&gt;<span class='lsp'>someValue)<span class='lsp-result'>let someValue: any</span></span>.<span class='lsp'>length;<span class='lsp-result'>(property) String.length: number</span></span></span></code></div></pre>\n<p>And the other is the <code>as</code>-syntax:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>someValue:<span class='lsp-result'>let someValue: any</span></span> any = </span><span style=\"color: #A31515\">\"this is a string\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> <span class='lsp'>strLength:<span class='lsp-result'>let strLength: number</span></span> number = (<span class='lsp'>someValue <span class='lsp-result'>let someValue: any</span></span></span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> string).<span class='lsp'>length;<span class='lsp-result'>(property) String.length: number</span></span></span></code></div></pre>\n<p>The two samples are equivalent.\nUsing one over the other is mostly a choice of preference; however, when using TypeScript with JSX, only <code>as</code>-style assertions are allowed.</p>\n<h1 id=\"a-note-about-let\" style=\"position:relative;\"><a href=\"#a-note-about-let\" aria-label=\"a note about let 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>A note about <code>let</code></h1>\n<p>You may’ve noticed that so far, we’ve been using the <code>let</code> keyword instead of JavaScript’s <code>var</code> keyword which you might be more familiar with.\nThe <code>let</code> keyword is actually a newer JavaScript construct that TypeScript makes available.\nWe’ll discuss the details later, but many common problems in JavaScript are alleviated by using <code>let</code>, so you should use it instead of <code>var</code> whenever possible.</p>","headings":[{"value":"Introduction","depth":1},{"value":"Boolean","depth":1},{"value":"Number","depth":1},{"value":"String","depth":1},{"value":"Array","depth":1},{"value":"Tuple","depth":1},{"value":"Enum","depth":1},{"value":"Any","depth":1},{"value":"Void","depth":1},{"value":"Null and Undefined","depth":1},{"value":"Never","depth":1},{"value":"Object","depth":1},{"value":"Type assertions","depth":1},{"value":"A note about let","depth":1}],"frontmatter":{"permalink":"/docs/handbook/basic-types.html","title":"Basic Types"}}},"pageContext":{"slug":"/docs/handbook/basic-types.html","isOldHandbook":true}}}