{"componentChunkName":"component---src-templates-documentation-tsx","path":"/docs/handbook/type-checking-javascript-files.html","result":{"data":{"allSitePage":{"nodes":[{"path":"/dev-404-page/"},{"path":"/docs/handbook/nightly-builds.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/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/basic-types.html"},{"path":"/docs/handbook/classes.html"},{"path":"/docs/handbook/enums.html"},{"path":"/docs/handbook/functions.html"},{"path":"/docs/handbook/generics.html"},{"path":"/docs/handbook/interfaces.html"},{"path":"/docs/handbook/literal-types.html"},{"path":"/docs/handbook/intro.html"},{"path":"/docs/handbook/unions-and-intersections.html"},{"path":"/docs/handbook/declaration-files/dts-from-js.html"},{"path":"/docs/handbook/intro-to-js-ts.html"},{"path":"/docs/handbook/jsdoc-supported-types.html"},{"path":"/docs/handbook/type-checking-javascript-files.html"},{"path":"/docs/handbook/compiler-options-in-msbuild.html"},{"path":"/docs/handbook/compiler-options.html"},{"path":"/docs/handbook/configuring-watch.html"},{"path":"/docs/handbook/integrating-with-build-tools.html"},{"path":"/docs/handbook/project-references.html"},{"path":"/docs/handbook/tsconfig-json.html"},{"path":"/docs/handbook/advanced-types.html"},{"path":"/docs/handbook/declaration-merging.html"},{"path":"/docs/handbook/decorators.html"},{"path":"/docs/handbook/iterators-and-generators.html"},{"path":"/docs/handbook/jsx.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/symbols.html"},{"path":"/docs/handbook/triple-slash-directives.html"},{"path":"/docs/handbook/type-compatibility.html"},{"path":"/docs/handbook/type-inference.html"},{"path":"/docs/handbook/utility-types.html"},{"path":"/docs/handbook/variable-declarations.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-1.html"},{"path":"/docs/handbook/release-notes/typescript-2-2.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/release-notes/typescript-3-9.html"},{"path":"/docs/handbook/asp-net-core.html"},{"path":"/docs/handbook/angular.html"},{"path":"/docs/handbook/babel-with-typescript.html"},{"path":"/docs/handbook/dom-manipulation.html"},{"path":"/docs/handbook/gulp.html"},{"path":"/docs/handbook/migrating-from-javascript.html"},{"path":"/docs/handbook/react.html"},{"path":"/docs/handbook/typescript-tooling-in-5-minutes.html"},{"path":"/vo/docs/handbook/basic-types.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":"/vo/tsconfig"},{"path":"/tsconfig"},{"path":"/en/tsconfig"},{"path":"/ja/tsconfig"},{"path":"/pt/tsconfig"},{"path":"/play"},{"path":"/en/play"},{"path":"/es/play"},{"path":"/fa/play"},{"path":"/pt/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/4-0/new-checks/class-constructor-code-flow.ts"},{"path":"/play/4-0/new-js-features/jsdoc-deprecated.ts"},{"path":"/play/4-0/new-js-features/logical-operators-and-assignment.ts"},{"path":"/play/4-0/new-js-features/nullish-coalescing.ts"},{"path":"/play/4-0/new-ts-features/named-tuples.ts"},{"path":"/play/4-0/new-ts-features/unknown-in-catch.ts"},{"path":"/play/4-0/new-ts-features/variadic-tuples.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/language/soundness.ts"},{"path":"/es/play/typescript/language/structural-typing.ts"},{"path":"/es/play/typescript/language/type-guards.ts"},{"path":"/es/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/es/play/typescript/meta-types/conditional-types.ts"},{"path":"/es/play/typescript/meta-types/discriminate-types.ts"},{"path":"/es/play/typescript/meta-types/indexed-types.ts"},{"path":"/es/play/typescript/meta-types/mapped-types.ts"},{"path":"/es/play/typescript/primitives/any.ts"},{"path":"/es/play/typescript/primitives/literals.ts"},{"path":"/es/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/es/play/typescript/primitives/unknown-and-never.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":"/fa/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/ja/play/3-7/fixits/big-number-literals.ts"},{"path":"/ja/play/3-7/syntax-and-messaging/nullish-coalescing.ts"},{"path":"/ja/play/3-7/syntax-and-messaging/optional-chaining.ts"},{"path":"/ja/play/3-8/breaking-changes/checking-unions-with-index-signatures.ts"},{"path":"/ja/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/ja/play/typescript/language-extensions/enums.ts"},{"path":"/ja/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/ja/play/3-7/fixits/infer-from-usage-changes.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/primitives/unknown-and-never.ts"},{"path":"/ja/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/ja/play/3-7/syntax-and-messaging/flattened-error-reporting.ts"},{"path":"/ja/play/3-7/fixits/const-to-let.ts"},{"path":"/ja/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/ja/play/typescript/type-primitives/nullable-types.ts"},{"path":"/ja/play/typescript/type-primitives/tuples.ts"},{"path":"/pt/play/3-7/fixits/big-number-literals.ts"},{"path":"/pt/play/3-7/fixits/const-to-let.ts"},{"path":"/pt/play/3-7/fixits/infer-from-usage-changes.ts"},{"path":"/pt/play/3-7/syntax-and-messaging/flattened-error-reporting.ts"},{"path":"/pt/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/pt/play/javascript/javascript-essentials/functions.ts"},{"path":"/pt/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/pt/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/pt/play/typescript/language-extensions/enums.ts"},{"path":"/pt/play/typescript/type-primitives/tuples.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/javascript-essentials/objects-and-arrays.ts"},{"path":"/zh/play/javascript/modern-javascript/async-await.ts"},{"path":"/zh/play/javascript/modern-javascript/immutability.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":"/community"},{"path":"/es/community"},{"path":"/ja/community"},{"path":"/pt/community"},{"path":"/vo/community"},{"path":"/zh/community"},{"path":"/download"},{"path":"/es/download"},{"path":"/ja/download"},{"path":"/pt/download"},{"path":"/vo/download"},{"path":"/zh/download"},{"path":"/empty"},{"path":"/es/empty"},{"path":"/ja/empty"},{"path":"/pt/empty"},{"path":"/vo/empty"},{"path":"/zh/empty"},{"path":"/"},{"path":"/es/"},{"path":"/ja/"},{"path":"/pt/"},{"path":"/vo/"},{"path":"/zh/"},{"path":"/tools"},{"path":"/es/tools"},{"path":"/ja/tools"},{"path":"/pt/tools"},{"path":"/vo/tools"},{"path":"/zh/tools"},{"path":"/why-create-typescript"},{"path":"/es/why-create-typescript"},{"path":"/ja/why-create-typescript"},{"path":"/pt/why-create-typescript"},{"path":"/vo/why-create-typescript"},{"path":"/zh/why-create-typescript"},{"path":"/docs/bootstrap"},{"path":"/es/docs/bootstrap"},{"path":"/ja/docs/bootstrap"},{"path":"/pt/docs/bootstrap"},{"path":"/vo/docs/bootstrap"},{"path":"/zh/docs/bootstrap"},{"path":"/docs/"},{"path":"/es/docs/"},{"path":"/ja/docs/"},{"path":"/pt/docs/"},{"path":"/vo/docs/"},{"path":"/zh/docs/"},{"path":"/docs/handbook/"},{"path":"/es/docs/handbook/"},{"path":"/ja/docs/handbook/"},{"path":"/pt/docs/handbook/"},{"path":"/vo/docs/handbook/"},{"path":"/zh/docs/handbook/"},{"path":"/branding/"},{"path":"/dev/bug-workbench/"},{"path":"/dev/playground-plugins/"},{"path":"/dev/sandbox/"},{"path":"/dev/twoslash/"},{"path":"/dev/typescript-vfs/"},{"path":"/upcoming/"}]},"markdownRemark":{"id":"e54f8f34-62e3-59fe-b616-960923e66185","excerpt":"Here are some notable differences on how checking works in .js files compared to .ts files. Properties are inferred from assignments in class bodies ES2015 does…","html":"<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=\"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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> <data-lsp lsp='class C'>C</data-lsp> {</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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorOnly: number'>constructorOnly</data-lsp></span><span style=\"color: #000000\"> = </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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorUnknown: string | undefined'>constructorUnknown</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\"><data-lsp lsp='var undefined'>undefined</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  <data-lsp lsp='(method) C.method(): void'>method</data-lsp>() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorOnly: number'>constructorOnly</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Type 'boolean' is not assignable to type 'number'.</span><span class=\"code\">2322</span></span><span class=\"error-behind\">Type 'boolean' is not assignable to type 'number'.</span><span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorUnknown: string | undefined'>constructorUnknown</data-lsp></span><span style=\"color: #000000\"> = </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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.methodOnly: string | boolean | undefined'>methodOnly</data-lsp></span><span style=\"color: #000000\"> = </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\">  <data-lsp lsp='(method) C.method2(): void'>method2</data-lsp>() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.methodOnly: string | boolean | undefined'>methodOnly</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// also, ok, methodOnly&apos;s type is string | boolean | undefined</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEGMAsFNINYCkDOAoEFYCdsHtsUAuUAJgGZTS1IAbAQxRVAGFQBvNUUSPAOxQAXbAFdIgggAoAlBy7dQg6AEsUAOl4DhYidgDyfWgE9QAXlAAGANzzuS1Rv5DR4ggFU+CPngDufM6AifAAmsABmynywwTbcAL7yALawSnjBMnIKiirqms46BAbGAWH0tCiwsQr2uU7artgeXr7+5gBEAA60QQgARvSCbVagmHgIADQ8dS66Td5+oKqgzpEA5qAAPoEh4ZHRttkOyanBRSbtY0MjYGOTvSKCoMfQaWdTIrTBoGUoeKC9sG2oQiUWC8gS3GeaVIGU4WRqaihp0M50Uokq12+5Twk1uTxSL2RxgA5MxBEYOoClis+Ostr08HhaLB6P4tkFgXswfE0HEgA'>Try</a></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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> <data-lsp lsp='class C'>C</data-lsp> {</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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.prop: number | undefined'>prop</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\"><data-lsp lsp='var undefined'>undefined</data-lsp></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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.count: number | undefined'>count</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module c&amp;#13;let c: C'>c</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> <data-lsp lsp='constructor C(): C'>C</data-lsp>();</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module c&amp;#13;let c: C'>c</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.prop: number | undefined'>prop</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module c&amp;#13;let c: C'>c</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.count: number | undefined'>count</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Type '\"string\"' is not assignable to type 'number | undefined'.</span><span class=\"code\">2322</span></span><span class=\"error-behind\">Type '\"string\"' is not assignable to type 'number | undefined'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEGMAsFNINYCkDOAoEFYCdsHtsUAuUAJgGZTS1IAbAQxRVAGFQBvNUUSPAOxQAXbAFdIgggAoAlBy7dQwAFRKIggJ4AHWBz4iAtgCMcoAD6gRfACawAZgEs+sKwF9QS4PO6Do9lADpNfE1QAF4LaztHZwBuL0UVNS0ddj0jE3NLGwcnV3dPBVAfP39eS0E47hc0arRaWEEeMNAnAHdWGTjIQODmgAYYxTAAeQBpGlK8cuaAIiFsRwBzGZigA'>Try</a></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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function C(): void'>C</data-lsp>() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\"><data-err>this</data-err></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorOnly: number'>constructorOnly</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>'this' implicitly has type 'any' because it does not have a type annotation.</span><span class=\"code\">2683</span></span><span class=\"error-behind\">'this' implicitly has type 'any' because it does not have a type annotation.</span><span style=\"color: #000000\">  </span><span style=\"color: #0000FF\"><data-err>this</data-err></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorUnknown: string | undefined'>constructorUnknown</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\"><data-lsp lsp='var undefined'>undefined</data-lsp></span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>'this' implicitly has type 'any' because it does not have a type annotation.</span><span class=\"code\">2683</span></span><span class=\"error-behind\">'this' implicitly has type 'any' because it does not have a type annotation.</span><span style=\"color: #000000\">}</span>\n<span style=\"color: #000000\"><data-lsp lsp='class C&amp;#13;function C(): void'>C</data-lsp>.<data-lsp lsp='(property) Function.prototype: any'>prototype</data-lsp>.<data-lsp lsp='(method) C.method(): void'>method</data-lsp> = </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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorOnly: number'>constructorOnly</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Type 'boolean' is not assignable to type 'number'.</span><span class=\"code\">2322</span></span><span class=\"error-behind\">Type 'boolean' is not assignable to type 'number'.</span><span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) C.constructorUnknown: string | undefined'>constructorUnknown</data-lsp></span><span style=\"color: #000000\"> = </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><a href='https://www.typescriptlang.org/play/#code/PTAEAEGMAsFNINYCkDOAoEFYCdsHtsUAuUAJgDYAOAZjOtNLQDMBXAO0gBcBLPN0AMIAKAJSgA3mlChO0bigB0kPik7YWXAgHk2AGwCeoALygADAG4pMuYuVtV6zdgCqbBGzwB3fifYATWCZuNlg-SwBfNAEFAAd8TjxOfRjYBQBbWFk8P2NQVg4ePlBRCStZeSUVNQ0E7B0DXKYAQ10UWEtpctsqx1rXdy8fUAAiGN12BAAjJs5h81BMLQBpABprWBlkjflQB2CAc1AAH1B-QODQtHDzIA'>Try</a></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\"> </span><span style=\"color: #1A1A1A\">fs</span><span style=\"color: #000000\"> = 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\"> (</span><span style=\"color: #1A1A1A\">f</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> fs.readFileSync(</span><span style=\"color: #1A1A1A\">f</span><span style=\"color: #000000\">);</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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> <data-lsp lsp='class C&amp;#13;module C'>C</data-lsp> {}</span>\n<span style=\"color: #000000\"><data-lsp lsp='class C&amp;#13;module C'>C</data-lsp>.<data-lsp lsp='(property) C.D: typeof D'>D</data-lsp> = </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> {};</span></code><a href='https://www.typescriptlang.org/play/#code/MYGwhgzhAEDC0G8C+AoWA6AItAvNUkMyA3EA'>Try</a></div></pre>\n<p>And, for pre-ES2015 code, it can be used to simulate static methods:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function Outer(): void&amp;#13;module Outer'>Outer</data-lsp>() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.<data-lsp lsp='(property) Outer.y: number'>y</data-lsp> = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #1A1A1A\"><data-lsp lsp='class Outer&amp;#13;module Outer&amp;#13;function Outer(): void'>Outer</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Outer.Inner(): void'>Inner</data-lsp> = </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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) Inner.yy: number'>yy</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #1A1A1A\"><data-lsp lsp='class Outer&amp;#13;module Outer&amp;#13;function Outer(): void'>Outer</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='any'>innter</data-lsp>();</span></code><a href='https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAeRFApgJwBQEpEDeAUIolABYwDOAdAJ6IC8iATANxEC+RRqGmNAJJgwWJolCRYCRHkIkylWnQbN2XDrzRYaMEfzxsgA'>Try</a></div></pre>\n<p>It can also be used to create simple namespaces:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module ns&amp;#13;var ns: typeof ns'>ns</data-lsp></span><span style=\"color: #000000\"> = {};</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module ns&amp;#13;var ns: typeof ns'>ns</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(property) ns.C: typeof C'>C</data-lsp> = </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> {};</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module ns&amp;#13;var ns: typeof ns'>ns</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) ns.func(): void'>func</data-lsp> = </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {};</span>\n\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module ns&amp;#13;var ns: typeof ns'>ns</data-lsp></span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/G4QwTgBAdgzhC8EDeBfA3AKFgOgMIIgGMAbEGOVTHAMwFcpCC6GAXASwHsoIAKASmToMWGGiA'>Try</a></div></pre>\n<p>Other variants are allowed as well:</p>\n<pre class=\"shiki twoslash\"><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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module ns&amp;#13;var ns: {}'>ns</data-lsp></span><span style=\"color: #000000\"> = (</span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> (</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) n: undefined'>n</data-lsp></span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) n: undefined'>n</data-lsp></span><span style=\"color: #000000\"> || {};</span>\n<span style=\"color: #000000\">})();</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module ns&amp;#13;var ns: {}'>ns</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='any'>CONST</data-lsp> = </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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module assign&amp;#13;var assign: {&amp;#13;    (): void;&amp;#13;    extra: number;&amp;#13;}'>assign</data-lsp></span><span style=\"color: #000000\"> =</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module assign&amp;#13;var assign: {&amp;#13;    (): void;&amp;#13;    extra: number;&amp;#13;}'>assign</data-lsp></span><span style=\"color: #000000\"> ||</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: #1A1A1A\"><data-lsp lsp='module assign&amp;#13;var assign: {&amp;#13;    (): void;&amp;#13;    extra: number;&amp;#13;}'>assign</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) assign.extra: number'>extra</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEElwMQUQKAG4EMBOoB2BnUBeUAKAMwFd0BjAFwEsB7dA9ASlAG85RQUBTC4le+gB9BrAL4BuOKMb5GkrADoAwgHkAcgGUAKrlABGSXBCgAJl0JJiAG2roA5qAo1QdqzQBGSK4lSgkmTCo7ehx2PwCgoUEwknJqOgJmNg4OYzIaMxcaLmwACy5uMIk4f0DghS4ADwoUJF0DIA'>Try</a></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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module obj&amp;#13;var obj: {&amp;#13;    a: number;&amp;#13;}'>obj</data-lsp></span><span style=\"color: #000000\"> = { <data-lsp lsp='(property) a: number'>a</data-lsp>: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module obj&amp;#13;var obj: {&amp;#13;    a: number;&amp;#13;}'>obj</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='any'>b</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Allowed</span></code><a href='https://www.typescriptlang.org/play/#code/G4QwTgBA9gRgVhAvBA3hEAuCBGCBfAbgChY4A6GJCAJgIgHp6IBBAG1agHcBTAEyA'>Try</a></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 twoslash\"><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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='module obj&amp;#13;var obj: {&amp;#13;    a: number;&amp;#13;}'>obj</data-lsp></span><span style=\"color: #000000\"> = { <data-lsp lsp='(property) a: number'>a</data-lsp>: </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"> };</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='module obj&amp;#13;var obj: {&amp;#13;    a: number;&amp;#13;}'>obj</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-err><data-lsp lsp='any'>b</data-lsp></data-err></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Property 'b' does not exist on type '{ a: number; }'.</span><span class=\"code\">2339</span></span><span class=\"error-behind\">Property 'b' does not exist on type '{ a: number; }'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEGMAsFNINYCkDOAoEFYCdsHtsUAuUAJgGZyBODAKlogBcBPAB1lAG9OBDEgOwCuAWwBGOAL4TQtYGgBuPbKDyiAVqAC8XUH1ABGUBIDcaVWoB0orWWNA'>Try</a></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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function Foo(i?: any): void'>Foo</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) i: any'>i</data-lsp></span><span style=\"color: #000000\"> = </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\"> (!</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) i: any'>i</data-lsp></span><span style=\"color: #000000\">) </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) i: any'>i</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) j: any'>j</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\"><data-lsp lsp='var undefined'>undefined</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) j: any'>j</data-lsp></span><span style=\"color: #000000\"> = </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\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) Foo.l: any[]'>l</data-lsp></span><span style=\"color: #000000\"> = [];</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='var foo: Foo'>foo</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> <data-lsp lsp='constructor Foo(i?: any): Foo'>Foo</data-lsp>();</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='var foo: Foo'>foo</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) Foo.l: any[]'>l</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Array&amp;lt;any>.push(...items: any[]): number'>push</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='var foo: Foo'>foo</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='any'>i</data-lsp></span><span style=\"color: #000000\">);</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='var foo: Foo'>foo</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(property) Foo.l: any[]'>l</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Array&amp;lt;any>.push(...items: any[]): number'>push</data-lsp>(</span><span style=\"color: #A31515\">\"end\"</span><span style=\"color: #000000\">);</span></code><a href='https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAMTnAFDRBeRYQA2BAlIgN4BQiiMwi6AhDKVrgIwDcViAbgIYAnRACscicABMApsBhgpErtVG4ATEsRQAFjADOAOgJiA2gF0uAXwoV+Q4GjHyA7ijTpiXe3EP6ADiF0tdC99Zk80H39A9AAiKTAJGI8gA'>Try</a></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 twoslash\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function bar(a: any, b: any): void'>bar</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) a: any'>a</data-lsp></span><span style=\"color: #000000\">, </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) b: any'>b</data-lsp></span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  <data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) a: any'>a</data-lsp></span><span style=\"color: #000000\"> + </span><span style=\"color: #A31515\">\" \"</span><span style=\"color: #000000\"> + </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) b: any'>b</data-lsp></span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\"><data-lsp lsp='function bar(a: any, b: any): void'>bar</data-lsp>(</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\"><data-lsp lsp='function bar(a: any, b: any): void'>bar</data-lsp>(</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\"><data-lsp lsp='function bar(a: any, b: any): void'>bar</data-lsp>(</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\"><data-err>3</data-err></span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// Error, too many arguments</span>\n<span class=\"error\"><span>Expected 0-2 arguments, but got 3.</span><span class=\"code\">2554</span></span><span class=\"error-behind\">Expected 0-2 arguments, but got 3.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEGMAsFNINYCkDOAoEEUBcBOBLSbALlADMBDAGxVgzHFl1wHtcVSB2ABm4DZQPfqABMAVjEAWNGQCuAOyL4W80ACMKuABQUANOoCUoAN5pQoSCpQsqsAHRUWAcx2gA1KABEX94YDcaAC+aGga2gCMBn6gmADyANL6tJbyACagmk6yALaw8tgWVvipTLDpLAAO2Mry1KGaWuH6IlH1Ec36AMxRMWAAosxs+tgsLKDZFPIAnhm4Wbn5KEA'>Try</a></div></pre>\n<p>JSDoc annotated functions are excluded from this rule.\nUse JSDoc optional parameter syntax (<code>[</code> <code>]</code>) to express optionality. e.g.:</p>\n<pre class=\"shiki twoslash\"><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} </span><span style=\"color: #1A1A1A\">[somebody]</span><span style=\"color: #008000\"> - Somebody&apos;s name.</span>\n<span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function sayHello(somebody?: string | undefined): void'>sayHello</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) somebody: string | undefined'>somebody</data-lsp></span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (!</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) somebody: string | undefined'>somebody</data-lsp></span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) somebody: string | undefined'>somebody</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #A31515\">\"John Doe\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  <data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #A31515\">\"Hello \"</span><span style=\"color: #000000\"> + </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) somebody: string'>somebody</data-lsp></span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\"><data-lsp lsp='function sayHello(somebody?: string | undefined): void'>sayHello</data-lsp>();</span></code><a href='https://www.typescriptlang.org/play/#code/PQKhCgAIUgBAHAhgJ0QW0gbwM4BdkCWAdgOYC+kA2tgPZoCmARjQCYCeAupALSQDKdJqzYBybJCLp6AOighg4AGYBXIgGNcBGkUjZEbABL0ANsZoAKWg2bsAlFiiQCiyOYCEVoXYeRfuwTZskAC8kABEAFI0ABY6ACI09GEA3I5kjmratMYyZiTmYUamNOGQANT+1sK2qengeoYmZuY1QA'>Try</a></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 twoslash\"><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} </span><span style=\"color: #1A1A1A\">args</span><span style=\"color: #008000\"> */</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function sum(...args: number[]): number'>sum</data-lsp>(</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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) total: number'>total</data-lsp></span><span style=\"color: #000000\"> = </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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) i: number'>i</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">; </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) i: number'>i</data-lsp></span><span style=\"color: #000000\"> &lt; </span><span style=\"color: #0000FF\"><data-lsp lsp='(local var) arguments: IArguments'>arguments</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(property) IArguments.length: number'>length</data-lsp>; </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) i: number'>i</data-lsp></span><span style=\"color: #000000\">++) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) total: number'>total</data-lsp></span><span style=\"color: #000000\"> += </span><span style=\"color: #0000FF\"><data-lsp lsp='(local var) arguments: IArguments'>arguments</data-lsp></span><span style=\"color: #000000\">[</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) i: number'>i</data-lsp></span><span style=\"color: #000000\">];</span>\n<span style=\"color: #000000\">  }</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(local var) total: number'>total</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span></code><a href='https://www.typescriptlang.org/play/#code/PQKhAIAEAcEMCdYFtwG8B0mB2BXJAjAU3gF9wEBzAZ3BGACgAzHLAYwBcBLAey3CrwAKUOFwFiNOgEo09cOABuCcO27tYAG3ABecAAYA3HPCNu8cIKXnOO-QfA2APOXgU8hLOyroNHiuwALe04AahCZVGN5VXUtEN1Kd08qAG1OAF0jeRJjeEJ2HHg+GM0jEiA'>Try</a></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\"> { </span><span style=\"color: #1A1A1A\">Component</span><span style=\"color: #000000\"> } </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\">.</span><span style=\"color: #1A1A1A\">props</span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\">b</span><span style=\"color: #000000\">; </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\"> { </span><span style=\"color: #1A1A1A\">Component</span><span style=\"color: #000000\"> } </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\">.</span><span style=\"color: #1A1A1A\">props</span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\">b</span><span style=\"color: #000000\">; </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 twoslash\"><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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='var x: any[]'>x</data-lsp></span><span style=\"color: #000000\"> = [];</span>\n\n<span style=\"color: #1A1A1A\"><data-lsp lsp='var x: any[]'>x</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Array&amp;lt;any>.push(...items: any[]): number'>push</data-lsp>(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='var x: any[]'>x</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Array&amp;lt;any>.push(...items: any[]): number'>push</data-lsp>(</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\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='var y: number[]'>y</data-lsp></span><span style=\"color: #000000\"> = [];</span>\n\n<span style=\"color: #1A1A1A\"><data-lsp lsp='var y: number[]'>y</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Array&amp;lt;number>.push(...items: number[]): number'>push</data-lsp>(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">); </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='var y: number[]'>y</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) Array&amp;lt;number>.push(...items: number[]): number'>push</data-lsp>(</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><a href='https://www.typescriptlang.org/play/#code/PQKhAIAEBcE8AcCmBvAggJ3QQ1gX3CMAFABuW64AHuALzgDaAugNxFGUB08ArgM4AWACgCMASmbhgwcAHkA0uy58hAIl7R0ASwB2AcxXjJ0+QBoq4Tb3AB7AGbg4ScBmywAPFm2wAfG1AQYBBQXHA43bW4AWwAjRHRvfEJScnBYWgYWNlglARFDKVkFbJ5ctQ0dfXzpAFFMa3QzdS09Cytta2hwLF5eTV1tLGiAG0QHa3AImLigA'>Try</a></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\"> </span><span style=\"color: #1A1A1A\">p</span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Promise((</span><span style=\"color: #1A1A1A\">resolve</span><span style=\"color: #000000\">, </span><span style=\"color: #1A1A1A\">reject</span><span style=\"color: #000000\">) </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: #1A1A1A\">p</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Promise&lt;any&gt;;</span></code></div></pre>\n<p>To learn all of the features available in JSDoc, see <a href=\"/docs/handbook/jsdoc-supported-types.html\">the reference</a>.</p>","headings":[{"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}],"frontmatter":{"permalink":"/docs/handbook/type-checking-javascript-files.html","title":"Type Checking JavaScript Files","disable_toc":null,"oneline":"How to add type checking to JavaScript files using TypeScript"}},"prev":{"childMarkdownRemark":{"frontmatter":{"title":"JS Projects Utilizing TypeScript","oneline":"How to add type checking to JavaScript files using TypeScript","permalink":"/docs/handbook/intro-to-js-ts.html"}}},"next":{"childMarkdownRemark":{"frontmatter":{"title":"JSDoc Reference","oneline":"What JSDoc does TypeScript-powered JavaScript support?","permalink":"/docs/handbook/jsdoc-supported-types.html"}}}},"pageContext":{"id":"type-checking-javascript-files","slug":"/docs/handbook/type-checking-javascript-files.html","repoPath":"/packages/documentation/copy/en/javascript/Type Checking JavaScript Files.md","previousID":"2ae8d451-c272-55d5-ba61-816453b84a6a","nextID":"d848604c-bb7a-5209-9b14-87b5d859b2fc","lang":"en","modifiedTime":"2020-08-18T13:59:43.508Z"}}}