{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/type-checking-javascript-files.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":"099c212b-88e8-5f46-8b57-e1360a6c9382","excerpt":"TypeScript 2.3 and later support type-checking and reporting errors in .js files with --checkJs. You can skip checking some files by adding a // @ts-nocheck…","html":"<p>TypeScript 2.3 and later support type-checking and reporting errors in <code>.js</code> files with <code>--checkJs</code>.</p>\n<p>You can skip checking some files by adding a <code>// @ts-nocheck</code> comment to them; conversely, you can choose to check only a few <code>.js</code> files by adding a <code>// @ts-check</code> comment to them without setting <code>--checkJs</code>.\nYou can also ignore errors on specific lines by adding <code>// @ts-ignore</code> on the preceding line.\nNote that if you have a <code>tsconfig.json</code>, JS checking will respect strict flags like <code>noImplicitAny</code>, <code>strictNullChecks</code>, etc.\nHowever, because of the relative looseness of JS checking, combining strict flags with it may be surprising.</p>\n<p>Here are some notable differences on how checking works in <code>.js</code> files compared to <code>.ts</code> files:</p>\n<h2 id=\"jsdoc-types-are-used-for-type-information\" style=\"position:relative;\"><a href=\"#jsdoc-types-are-used-for-type-information\" aria-label=\"jsdoc types are used for type information 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 types are used for type information</h2>\n<p>In a <code>.js</code> file, types can often be inferred just like in <code>.ts</code> files.\nLikewise, when types can’t be inferred, they can be specified using JSDoc the same way that type annotations are used in a <code>.ts</code> file.\nJust like Typescript, <code>--noImplicitAny</code> will give you errors on the places that the compiler could not infer a type.\n(With the exception of open-ended object literals; see below for details.)</p>\n<p>JSDoc annotations adorning a declaration will be used to set the type of that declaration. For example:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x;</span>\n\n<span style=\"color: #000000\">x = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">x = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error: boolean is not assignable to number</span></code></div></pre>\n<p>You can find the full list of supported JSDoc patterns <a href=\"#supported-jsdoc\">below</a>.</p>\n<h2 id=\"properties-are-inferred-from-assignments-in-class-bodies\" style=\"position:relative;\"><a href=\"#properties-are-inferred-from-assignments-in-class-bodies\" aria-label=\"properties are inferred from assignments in class bodies 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>Properties are inferred from assignments in class bodies</h2>\n<p>ES2015 does not have a means for declaring properties on classes. Properties are dynamically assigned, just like object literals.</p>\n<p>In a <code>.js</code> file, the compiler infers properties from property assignments inside the class body.\nThe type of a property is the type given in the constructor, unless it’s not defined there, or the type in the constructor is undefined or null.\nIn that case, the type is the union of the types of all the right-hand values in these assignments.\nProperties defined in the constructor are always assumed to exist, whereas ones defined just in methods, getters, or setters are considered optional.</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: #0000FF\">constructor</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorOnly = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorUnknown = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  method() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorOnly = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// error, constructorOnly is a number</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorUnknown = </span><span style=\"color: #A31515\">\"plunkbat\"</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// ok, constructorUnknown is string | undefined</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.methodOnly = </span><span style=\"color: #A31515\">\"ok\"</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// ok, but methodOnly could also be undefined</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  method2() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.methodOnly = </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// also, ok, methodOnly's type is string | boolean | undefined</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>If properties are never set in the class body, they are considered unknown.\nIf your class has properties that are only read from, add and then annotate a declaration in the constructor with JSDoc to specify the type.\nYou don’t even have to give a value if it will be initialised later:</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: #0000FF\">constructor</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number | undefined} */</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.prop = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number | undefined} */</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.count;</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\"> c = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> C();</span>\n<span style=\"color: #000000\">c.prop = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">c.count = </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error: string is not assignable to number|undefined</span></code></div></pre>\n<h2 id=\"constructor-functions-are-equivalent-to-classes\" style=\"position:relative;\"><a href=\"#constructor-functions-are-equivalent-to-classes\" aria-label=\"constructor functions are equivalent to classes 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>Constructor functions are equivalent to classes</h2>\n<p>Before ES2015, Javascript used constructor functions instead of classes.\nThe compiler supports this pattern and understands constructor functions as equivalent to ES2015 classes.\nThe property inference rules described above work exactly the same way.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> C() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorOnly = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorUnknown = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #000000\">C.prototype.method = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorOnly = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// error</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.constructorUnknown = </span><span style=\"color: #A31515\">\"plunkbat\"</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK, the type is string | undefined</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<h2 id=\"commonjs-modules-are-supported\" style=\"position:relative;\"><a href=\"#commonjs-modules-are-supported\" aria-label=\"commonjs modules are supported 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>CommonJS modules are supported</h2>\n<p>In a <code>.js</code> file, Typescript understands the CommonJS module format.\nAssignments to <code>exports</code> and <code>module.exports</code> are recognized as export declarations.\nSimilarly, <code>require</code> function calls are recognized as module imports. For example:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">// same as `import module \"fs\"`</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> fs = require(</span><span style=\"color: #A31515\">\"fs\"</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #008000\">// same as `export function readFile`</span>\n<span style=\"color: #000000\">module.exports.readFile = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">(f) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> fs.readFileSync(f);</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<p>The module support in Javascript is much more syntactically forgiving than Typescript’s module support.\nMost combinations of assignments and declarations are supported.</p>\n<h2 id=\"classes-functions-and-object-literals-are-namespaces\" style=\"position:relative;\"><a href=\"#classes-functions-and-object-literals-are-namespaces\" aria-label=\"classes functions and object literals are namespaces 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>Classes, functions, and object literals are namespaces</h2>\n<p>Classes are namespaces in <code>.js</code> files.\nThis can be used to nest classes, for example:</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\">C.D = </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> {};</span></code></div></pre>\n<p>And, for pre-ES2015 code, it can be used to simulate static methods:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> Outer() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.y = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #000000\">Outer.Inner = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.yy = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<p>It can also be used to create simple namespaces:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> ns = {};</span>\n<span style=\"color: #000000\">ns.C = </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> {};</span>\n<span style=\"color: #000000\">ns.func = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">() {};</span></code></div></pre>\n<p>Other variants are allowed as well:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">// IIFE</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> ns = (</span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">(n) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> n || {};</span>\n<span style=\"color: #000000\">})();</span>\n<span style=\"color: #000000\">ns.CONST = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #008000\">// defaulting to global</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> assign =</span>\n<span style=\"color: #000000\">  assign ||</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// code goes here</span>\n<span style=\"color: #000000\">  };</span>\n<span style=\"color: #000000\">assign.extra = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span></code></div></pre>\n<h2 id=\"object-literals-are-open-ended\" style=\"position:relative;\"><a href=\"#object-literals-are-open-ended\" aria-label=\"object literals are open ended 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 literals are open-ended</h2>\n<p>In a <code>.ts</code> file, an object literal that initializes a variable declaration gives its type to the declaration.\nNo new members can be added that were not specified in the original literal.\nThis rule is relaxed in a <code>.js</code> file; object literals have an open-ended type (an index signature) that allows adding and looking up properties that were not defined originally.\nFor instance:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> obj = { a: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #000000\">obj.b = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Allowed</span></code></div></pre>\n<p>Object literals behave as if they have an index signature <code>[x:string]: any</code> that allows them to be treated as open maps instead of closed objects.</p>\n<p>Like other special JS checking behaviors, this behavior can be changed by specifying a JSDoc type for the variable. For example:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {{a: number}} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> obj = { a: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #000000\">obj.b = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error, type {a: number} does not have property b</span></code></div></pre>\n<h2 id=\"null-undefined-and-empty-array-initializers-are-of-type-any-or-any\" style=\"position:relative;\"><a href=\"#null-undefined-and-empty-array-initializers-are-of-type-any-or-any\" aria-label=\"null undefined and empty array initializers are of type any or 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>null, undefined, and empty array initializers are of type any or any[]</h2>\n<p>Any variable, parameter or property that is initialized with null or undefined will have type any, even if strict null checks is turned on.\nAny variable, parameter or property that is initialized with [] will have type any[], even if strict null checks is turned on.\nThe only exception is for properties that have multiple initializers as described above.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> Foo(i = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (!i) i = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> j = </span><span style=\"color: #0000FF\">undefined</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  j = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.l = [];</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> foo = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Foo();</span>\n<span style=\"color: #000000\">foo.l.push(foo.i);</span>\n<span style=\"color: #000000\">foo.l.push(</span><span style=\"color: #A31515\">\"end\"</span><span style=\"color: #000000\">);</span></code></div></pre>\n<h2 id=\"function-parameters-are-optional-by-default\" style=\"position:relative;\"><a href=\"#function-parameters-are-optional-by-default\" aria-label=\"function parameters are optional by default 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>Function parameters are optional by default</h2>\n<p>Since there is no way to specify optionality on parameters in pre-ES2015 Javascript, all function parameters in <code>.js</code> file are considered optional.\nCalls with fewer arguments than the declared number of parameters are allowed.</p>\n<p>It is important to note that it is an error to call a function with too many arguments.</p>\n<p>For instance:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> bar(a, b) {</span>\n<span style=\"color: #000000\">  console.log(a + </span><span style=\"color: #A31515\">\" \"</span><span style=\"color: #000000\"> + b);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">bar(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK, second argument considered optional</span>\n<span style=\"color: #000000\">bar(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">bar(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error, too many arguments</span></code></div></pre>\n<p>JSDoc annotated functions are excluded from this rule.\nUse JSDoc optional parameter syntax to express optionality. e.g.:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} [somebody] - Somebody's name.</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> sayHello(somebody) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (!somebody) {</span>\n<span style=\"color: #000000\">    somebody = </span><span style=\"color: #A31515\">\"John Doe\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  console.log(</span><span style=\"color: #A31515\">\"Hello \"</span><span style=\"color: #000000\"> + somebody);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">sayHello();</span></code></div></pre>\n<h2 id=\"var-args-parameter-declaration-inferred-from-use-of-arguments\" style=\"position:relative;\"><a href=\"#var-args-parameter-declaration-inferred-from-use-of-arguments\" aria-label=\"var args parameter declaration inferred from use of arguments 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>Var-args parameter declaration inferred from use of <code>arguments</code></h2>\n<p>A function whose body has a reference to the <code>arguments</code> reference is implicitly considered to have a var-arg parameter (i.e. <code>(...arg: any[]) => any</code>). Use JSDoc var-arg syntax to specify the type of the arguments.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {...number} args */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> sum(</span><span style=\"color: #008000\">/* numbers */</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> total = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">for</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> i = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">; i &lt; </span><span style=\"color: #0000FF\">arguments</span><span style=\"color: #000000\">.length; i++) {</span>\n<span style=\"color: #000000\">    total += </span><span style=\"color: #0000FF\">arguments</span><span style=\"color: #000000\">[i];</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> total;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"unspecified-type-parameters-default-to-any\" style=\"position:relative;\"><a href=\"#unspecified-type-parameters-default-to-any\" aria-label=\"unspecified type parameters default to 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>Unspecified type parameters default to <code>any</code></h2>\n<p>Since there is no natural syntax for specifying generic type parameters in Javascript, an unspecified type parameter defaults to <code>any</code>.</p>\n<h3 id=\"in-extends-clause\" style=\"position:relative;\"><a href=\"#in-extends-clause\" aria-label=\"in extends clause 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>In extends clause</h3>\n<p>For instance, <code>React.Component</code> is defined to have two type parameters, <code>Props</code> and <code>State</code>.\nIn a <code>.js</code> file, there is no legal way to specify these in the extends clause. By default the type arguments will be <code>any</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { 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\">class</span><span style=\"color: #000000\"> MyComponent </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Component {</span>\n<span style=\"color: #000000\">  render() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.props.b; </span><span style=\"color: #008000\">// Allowed, since this.props is of type any</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Use JSDoc <code>@augments</code> to specify the types explicitly. for instance:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { 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: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@augments</span><span style=\"color: #008000\"> {Component&lt;{a: number}, State&gt;}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> MyComponent </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Component {</span>\n<span style=\"color: #000000\">  render() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.props.b; </span><span style=\"color: #008000\">// Error: b does not exist on {a:number}</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h3 id=\"in-jsdoc-references\" style=\"position:relative;\"><a href=\"#in-jsdoc-references\" aria-label=\"in jsdoc references 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>In JSDoc references</h3>\n<p>An unspecified type argument in JSDoc defaults to any:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\">{Array} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x = [];</span>\n\n<span style=\"color: #000000\">x.push(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">x.push(</span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK, x is of type Array&lt;any&gt;</span>\n\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\">{Array.&lt;number&gt;} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> y = [];</span>\n\n<span style=\"color: #000000\">y.push(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\">y.push(</span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error, string is not assignable to number</span></code></div></pre>\n<h3 id=\"in-function-calls\" style=\"position:relative;\"><a href=\"#in-function-calls\" aria-label=\"in function calls 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>In function calls</h3>\n<p>A call to a generic function uses the arguments to infer the type parameters. Sometimes this process fails to infer any types, mainly because of lack of inference sources; in these cases, the type parameters will default to <code>any</code>. For example:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> p = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Promise((resolve, reject) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">  reject();</span>\n<span style=\"color: #000000\">});</span>\n\n<span style=\"color: #000000\">p; </span><span style=\"color: #008000\">// Promise&lt;any&gt;;</span></code></div></pre>\n<h1 id=\"supported-jsdoc\" style=\"position:relative;\"><a href=\"#supported-jsdoc\" aria-label=\"supported jsdoc 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>Supported JSDoc</h1>\n<p>The list below outlines which constructs are currently supported when using JSDoc annotations to provide type information in JavaScript files.</p>\n<p>Note any tags which are not explicitly listed below (such as <code>@async</code>) are not yet supported.</p>\n<ul>\n<li><code>@type</code></li>\n<li><code>@param</code> (or <code>@arg</code> or <code>@argument</code>)</li>\n<li><code>@returns</code> (or <code>@return</code>)</li>\n<li><code>@typedef</code></li>\n<li><code>@callback</code></li>\n<li><code>@template</code></li>\n<li><code>@class</code> (or <code>@constructor</code>)</li>\n<li><code>@this</code></li>\n<li><code>@extends</code> (or <code>@augments</code>)</li>\n<li><code>@enum</code></li>\n</ul>\n<p>The meaning is usually the same, or a superset, of the meaning of the tag given at usejsdoc.org.\nThe code below describes the differences and gives some example usage of each tag.</p>\n<h2 id=\"type\" style=\"position:relative;\"><a href=\"#type\" aria-label=\"type permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>@type</code></h2>\n<p>You can use the “@type” tag and reference a type name (either primitive, defined in a TypeScript declaration, or in a JSDoc “@typedef” tag).\nYou can use any Typescript type, and most JSDoc types.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {string}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> s;</span>\n\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Window} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> win;</span>\n\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {PromiseLike&lt;string&gt;} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> promisedString;</span>\n\n<span style=\"color: #008000\">// You can specify an HTML Element with DOM properties</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {HTMLElement} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> myElement = document.querySelector(selector);</span>\n<span style=\"color: #000000\">element.dataset.myData = </span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">;</span></code></div></pre>\n<p><code>@type</code> can specify a union type — for example, something can be either a string or a boolean.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {(string | boolean)}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> sb;</span></code></div></pre>\n<p>Note that parentheses are optional for union types.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {string | boolean}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> sb;</span></code></div></pre>\n<p>You can specify array types using a variety of syntaxes:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number[]} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> ns;</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Array.&lt;number&gt;} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> nds;</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Array&lt;number&gt;} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> nas;</span></code></div></pre>\n<p>You can also specify object literal types.\nFor example, an object with properties ‘a’ (string) and ‘b’ (number) uses the following syntax:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {{ a: string, b: number }} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> var9;</span></code></div></pre>\n<p>You can specify map-like and array-like objects using string and number index signatures, using either standard JSDoc syntax or Typescript syntax.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * A map-like object that maps arbitrary `string` properties to `number`s.</span>\n<span style=\"color: #008000\"> *</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Object.&lt;string, number&gt;}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> stringToNumber;</span>\n\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Object.&lt;number, object&gt;} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> arrayLike;</span></code></div></pre>\n<p>The preceding two types are equivalent to the Typescript types <code>{ [x: string]: number }</code> and <code>{ [x: number]: any }</code>. The compiler understands both syntaxes.</p>\n<p>You can specify function types using either Typescript or Closure syntax:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {function(string, boolean): number} Closure syntax */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> sbn;</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {(s: string, b: boolean) =&gt; number} Typescript syntax */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> sbn2;</span></code></div></pre>\n<p>Or you can just use the unspecified <code>Function</code> type:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Function} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> fn7;</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {function} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> fn6;</span></code></div></pre>\n<p>Other types from Closure also work:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {*} - can be 'any' type</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> star;</span>\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {?} - unknown type (same as 'any')</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> question;</span></code></div></pre>\n<h3 id=\"casts\" style=\"position:relative;\"><a href=\"#casts\" aria-label=\"casts 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>Casts</h3>\n<p>Typescript borrows cast syntax from Closure.\nThis lets you cast types to other types by adding a <code>@type</code> tag before any parenthesized expression.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number | string}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> numberOrString = Math.random() &lt; </span><span style=\"color: #09835A\">0.5</span><span style=\"color: #000000\"> ? </span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\"> : </span><span style=\"color: #09835A\">100</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> typeAssertedNumber = </span><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {number} */</span><span style=\"color: #000000\"> (numberOrString);</span></code></div></pre>\n<h3 id=\"import-types\" style=\"position:relative;\"><a href=\"#import-types\" aria-label=\"import types permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Import types</h3>\n<p>You can also import declarations from other files using import types.\nThis syntax is Typescript-specific and differs from the JSDoc standard:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> p { import(\"./a\").Pet }</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> walk(p) {</span>\n<span style=\"color: #000000\">  console.log(</span><span style=\"color: #A31515\">`Walking ${p.name}...`</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>import types can also be used in type alias declarations:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@typedef</span><span style=\"color: #008000\"> { import(\"./a\").Pet } Pet</span>\n<span style=\"color: #008000\"> */</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Pet}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> myPet;</span>\n<span style=\"color: #000000\">myPet.name;</span></code></div></pre>\n<p>import types can be used to get the type of a value from a module if you don’t know the type, or if it has a large type that is annoying to type:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {typeof import(\"./a\").x }</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x = require(</span><span style=\"color: #A31515\">\"./a\"</span><span style=\"color: #000000\">).x;</span></code></div></pre>\n<h2 id=\"param-and-returns\" style=\"position:relative;\"><a href=\"#param-and-returns\" aria-label=\"param and returns 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>@param</code> and <code>@returns</code></h2>\n<p><code>@param</code> uses the same type syntax as <code>@type</code>, but adds a parameter name.\nThe parameter may also be declared optional by surrounding the name with square brackets:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">// Parameters may be declared in a variety of syntactic forms</span>\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string}  p1 - A string param.</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string=} p2 - An optional param (Closure syntax)</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} [p3] - Another optional param (JSDoc syntax).</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} [p4=\"test\"] - An optional param with a default value</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@return</span><span style=\"color: #008000\"> {string} This is the result</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> stringsStringStrings(p1, p2, p3, p4) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// TODO</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Likewise, for the return type of a function:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@return</span><span style=\"color: #008000\"> {PromiseLike&lt;string&gt;}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> ps() {}</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@returns</span><span style=\"color: #008000\"> {{ a: string, b: number }} - May use '</span><span style=\"color: #0000FF\">@returns</span><span style=\"color: #008000\">' as well as '</span><span style=\"color: #0000FF\">@return</span><span style=\"color: #008000\">'</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> ab() {}</span></code></div></pre>\n<h2 id=\"typedef-callback-and-param\" style=\"position:relative;\"><a href=\"#typedef-callback-and-param\" aria-label=\"typedef callback and param 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>@typedef</code>, <code>@callback</code>, and <code>@param</code></h2>\n<p><code>@typedef</code> may be used to define complex types.\nSimilar syntax works with <code>@param</code>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@typedef</span><span style=\"color: #008000\"> {Object} SpecialType - creates a new type named 'SpecialType'</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@property</span><span style=\"color: #008000\"> {string} prop1 - a string property of SpecialType</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@property</span><span style=\"color: #008000\"> {number} prop2 - a number property of SpecialType</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@property</span><span style=\"color: #008000\"> {number=} prop3 - an optional number property of SpecialType</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@prop</span><span style=\"color: #008000\"> {number} [prop4] - an optional number property of SpecialType</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@prop</span><span style=\"color: #008000\"> {number} [prop5=42] - an optional number property of SpecialType with default</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {SpecialType} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> specialTypeObject;</span></code></div></pre>\n<p>You can use either <code>object</code> or <code>Object</code> on the first line.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@typedef</span><span style=\"color: #008000\"> {object} SpecialType1 - creates a new type named 'SpecialType1'</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@property</span><span style=\"color: #008000\"> {string} prop1 - a string property of SpecialType1</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@property</span><span style=\"color: #008000\"> {number} prop2 - a number property of SpecialType1</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@property</span><span style=\"color: #008000\"> {number=} prop3 - an optional number property of SpecialType1</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {SpecialType1} */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> specialTypeObject1;</span></code></div></pre>\n<p><code>@param</code> allows a similar syntax for one-off type specifications.\nNote that the nested property names must be prefixed with the name of the parameter:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {Object} options - The shape is the same as SpecialType above</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} options.prop1</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number} options.prop2</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number=} options.prop3</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number} [options.prop4]</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number} [options.prop5=42]</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> special(options) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> (options.prop4 || </span><span style=\"color: #09835A\">1001</span><span style=\"color: #000000\">) + options.prop5;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><code>@callback</code> is similar to <code>@typedef</code>, but it specifies a function type instead of an object type:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@callback</span><span style=\"color: #008000\"> Predicate</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} data</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number} [index]</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@returns</span><span style=\"color: #008000\"> {boolean}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {Predicate} */</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> ok = s </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> !(s.length % </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p>Of course, any of these types can be declared using Typescript syntax in a single-line <code>@typedef</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@typedef</span><span style=\"color: #008000\"> {{ prop1: string, prop2: string, prop3?: number }} SpecialType */</span>\n<span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@typedef</span><span style=\"color: #008000\"> {(data: string, index?: number) =&gt; boolean} Predicate */</span></code></div></pre>\n<h2 id=\"template\" style=\"position:relative;\"><a href=\"#template\" aria-label=\"template 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>@template</code></h2>\n<p>You can declare generic types with the <code>@template</code> tag:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@template</span><span style=\"color: #008000\"> T</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {T} x - A generic parameter that flows through to the return type</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@return</span><span style=\"color: #008000\"> {T}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> id(x) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> x;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Use comma or multiple tags to declare multiple type parameters:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@template</span><span style=\"color: #008000\"> T,U,V</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@template</span><span style=\"color: #008000\"> W,X</span>\n<span style=\"color: #008000\"> */</span></code></div></pre>\n<p>You can also specify a type constraint before the type parameter name.\nOnly the first type parameter in a list is constrained:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@template</span><span style=\"color: #008000\"> {string} K - K must be a string or string literal</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@template</span><span style=\"color: #008000\"> {{ serious(): string }} Seriousalizable - must have a serious method</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {K} key</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {Seriousalizable} object</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> seriousalize(key, object) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// ????</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"constructor\" style=\"position:relative;\"><a href=\"#constructor\" aria-label=\"constructor 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>@constructor</code></h2>\n<p>The compiler infers constructor functions based on this-property assignments, but you can make checking stricter and suggestions better if you add a <code>@constructor</code> tag:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@constructor</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number} data</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> C(data) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.size = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.initialize(data); </span><span style=\"color: #008000\">// Should error, initializer expects a string</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} s</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #000000\">C.prototype.initialize = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">(s) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.size = s.length;</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> c = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> C(</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> result = C(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// C should only be called with new</span></code></div></pre>\n<p>With <code>@constructor</code>, <code>this</code> is checked inside the constructor function <code>C</code>, so you will get suggestions for the <code>initialize</code> method and an error if you pass it a number. You will also get an error if you call <code>C</code> instead of constructing it.</p>\n<p>Unfortunately, this means that constructor functions that are also callable cannot use <code>@constructor</code>.</p>\n<h2 id=\"this\" style=\"position:relative;\"><a href=\"#this\" aria-label=\"this permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>@this</code></h2>\n<p>The compiler can usually figure out the type of <code>this</code> when it has some context to work with. When it doesn’t, you can explicitly specify the type of <code>this</code> with <code>@this</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@this</span><span style=\"color: #008000\"> {HTMLElement}</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {*} e</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> callbackForLater(e) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.clientHeight = parseInt(e); </span><span style=\"color: #008000\">// should be fine!</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"extends\" style=\"position:relative;\"><a href=\"#extends\" aria-label=\"extends 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>@extends</code></h2>\n<p>When Javascript classes extend a generic base class, there is nowhere to specify what the type parameter should be. The <code>@extends</code> tag provides a place for that type parameter:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@template</span><span style=\"color: #008000\"> T</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@extends</span><span style=\"color: #008000\"> {Set&lt;T&gt;}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> SortableSet </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Set {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// ...</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Note that <code>@extends</code> only works with classes. Currently, there is no way for a constructor function extend a class.</p>\n<h2 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><code>@enum</code></h2>\n<p>The <code>@enum</code> tag allows you to create an object literal whose members are all of a specified type. Unlike most object literals in Javascript, it does not allow other members.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@enum</span><span style=\"color: #008000\"> {number} */</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> JSDocState = {</span>\n<span style=\"color: #000000\">  BeginningOfLine: </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  SawAsterisk: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  SavingComments: </span><span style=\"color: #09835A\">2</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<p>Note that <code>@enum</code> is quite different from, and much simpler than, Typescript’s <code>enum</code>. However, unlike Typescript’s enums, <code>@enum</code> can have any type:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@enum</span><span style=\"color: #008000\"> {function(number): number} */</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> Math = {</span>\n<span style=\"color: #000000\">  add1: n </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> n + </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  id: n </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> -n,</span>\n<span style=\"color: #000000\">  sub1: n </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> n - </span><span style=\"color: #09835A\">1</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<h2 id=\"more-examples\" style=\"position:relative;\"><a href=\"#more-examples\" aria-label=\"more examples 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>More examples</h2>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> someObj = {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\">   * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} param1 - Docs on property assignments work</span>\n<span style=\"color: #008000\">   */</span>\n<span style=\"color: #000000\">  x: </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">(param1) {}</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * As do docs on variable assignments</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@return</span><span style=\"color: #008000\"> {Window}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> someFunc = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\">() {};</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * And class methods</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {string} greeting The greeting to use</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #000000\">Foo.prototype.sayHi = greeting </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> console.log(</span><span style=\"color: #A31515\">\"Hi!\"</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * And arrow functions expressions</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {number} x - A multiplier</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> myArrow = x </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> x * x;</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * Which means it works for stateless function components in JSX too</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {{a: string, b: number}} test - Some param</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> fc = test </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> </span><span style=\"color: #800000\">&lt;div&gt;</span><span style=\"color: #000000\">{test.a.charAt(</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">)}</span><span style=\"color: #800000\">&lt;/div&gt;</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * A parameter can be a class constructor, using Closure syntax.</span>\n<span style=\"color: #008000\"> *</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {{new(...args: any[]): object}} C - The class to register</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> registerClass(C) {}</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {...string} p1 - A 'rest' arg (array) of strings. (treated as 'any')</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> fn10(p1) {}</span>\n\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@param</span><span style=\"color: #008000\"> {...string} p1 - A 'rest' arg (array) of strings. (treated as 'any')</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> fn9(p1) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> p1.join();</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"patterns-that-are-known-not-to-be-supported\" style=\"position:relative;\"><a href=\"#patterns-that-are-known-not-to-be-supported\" aria-label=\"patterns that are known not to be supported 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>Patterns that are known NOT to be supported</h2>\n<p>Referring to objects in the value space as types doesn’t work unless the object also creates a type, like a constructor function.</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> aNormalFunction() {}</span>\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {aNormalFunction}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> wrong;</span>\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * Use 'typeof' instead:</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {typeof aNormalFunction}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> right;</span></code></div></pre>\n<p>Postfix equals on a property type in an object literal type doesn’t specify an optional property:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {{ a: string, b: number= }}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> wrong;</span>\n<span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * Use postfix question on the property name instead:</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {{ a: string, b?: number }}</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> right;</span></code></div></pre>\n<p>Nullable types only have meaning if <code>strictNullChecks</code> is on:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {?number}</span>\n<span style=\"color: #008000\"> * With strictNullChecks: true -- number | null</span>\n<span style=\"color: #008000\"> * With strictNullChecks: off  -- number</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> nullable;</span></code></div></pre>\n<p>Non-nullable types have no meaning and are treated just as their original type:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #008000\">/**</span>\n<span style=\"color: #008000\"> * </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {!number}</span>\n<span style=\"color: #008000\"> * Just has type number</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> normal;</span></code></div></pre>\n<p>Unlike JSDoc’s type system, Typescript only allows you to mark types as containing null or not.\nThere is no explicit non-nullability — if strictNullChecks is on, then <code>number</code> is not nullable.\nIf it is off, then <code>number</code> is nullable.</p>","headings":[{"value":"JSDoc types are used for type information","depth":2},{"value":"Properties are inferred from assignments in class bodies","depth":2},{"value":"Constructor functions are equivalent to classes","depth":2},{"value":"CommonJS modules are supported","depth":2},{"value":"Classes, functions, and object literals are namespaces","depth":2},{"value":"Object literals are open-ended","depth":2},{"value":"null, undefined, and empty array initializers are of type any or any[]","depth":2},{"value":"Function parameters are optional by default","depth":2},{"value":"Var-args parameter declaration inferred from use of arguments","depth":2},{"value":"Unspecified type parameters default to any","depth":2},{"value":"In extends clause","depth":3},{"value":"In JSDoc references","depth":3},{"value":"In function calls","depth":3},{"value":"Supported JSDoc","depth":1},{"value":"@type","depth":2},{"value":"Casts","depth":3},{"value":"Import types","depth":3},{"value":"@param and @returns","depth":2},{"value":"@typedef, @callback, and @param","depth":2},{"value":"@template","depth":2},{"value":"@constructor","depth":2},{"value":"@this","depth":2},{"value":"@extends","depth":2},{"value":"@enum","depth":2},{"value":"More examples","depth":2},{"value":"Patterns that are known NOT to be supported","depth":2}],"frontmatter":{"permalink":"/docs/handbook/type-checking-javascript-files.html","title":"Type Checking JavaScript Files"}}},"pageContext":{"slug":"/docs/handbook/type-checking-javascript-files.html","isOldHandbook":true}}}