Help us improve these pages See how TypeScript improves day to day working with JavaScript with minimal additional syntax.Explore how TypeScript extends JavaScript to add more safety and tooling.// You can specify an HTML Element with DOM properties * A map-like object that maps arbitrary `string` properties to `number`s. */ function add (num1, num2) { return num1 + num2; } // missing brace // missing @returns tag /** * @param {string name Whom to … If a parameter accepts a callback function, you can use the The parameter type can be a built-in JavaScript type, such as string or Object, … * @param {number} num The first number. The following example shows the use of the @description, @param, and @return JSDoc tags for a function named getArea. There is no explicit non-nullability — if strictNullChecks is on, then The following tags have open issues to support them:How to add type checking to JavaScript files using TypeScriptThe TypeScript docs are an open source project. Optional parameter An optional parameter named foo. Be sure to include a space before and after the hyphen.The following examples show how to include names, types, and descriptions in a You can add a hyphen before the description to make it more readable. The @paramtag requires you to specify the name of the parameter you are documenting. {{new(...args: any[]): object}} C - The class to register - A 'rest' arg (array) of strings. /** @description Determines the area of a circle that has the specified radius parameter.

@param {number} [foo] // or: @param {number=} foo An optional parameter foo with default value 1. before and after the hyphen.If a parameter is expected to have a specific property, you can document that property by providing We will look into 4 different ways, each with their own uses, in this article. when using JSDoc annotations to provide type information in JavaScript files.Note any tags which are not explicitly listed below (such as The meaning is usually the same, or a superset, of the meaning of the tag given at You can use the “@type” tag and reference a type name (either primitive, defined in a TypeScript declaration, or in a JSDoc “@typedef” tag). This syntax is TypeScript-specific and differs from the JSDoc standard:import types can also be used in type alias declarations: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:Of course, any of these types can be declared using TypeScript syntax in a single-line Use comma or multiple tags to declare multiple type parameters:You can also specify a type constraint before the type parameter name. You can use most JSDoc types and any TypeScript type, from Note that parentheses are optional for union types.You can specify array types using a variety of syntaxes:You can also specify object literal types. {function(string, boolean): number} Closure syntax */ {(s: string, b: boolean) => number} TypeScript syntax */// Parameters may be declared in a variety of syntactic forms {string} [p4="test"] - An optional param with a default value {Object} SpecialType - creates a new type named 'SpecialType' {number=} prop3 - an optional number property of SpecialType {number} [prop4] - an optional number property of SpecialType {number} [prop5=42] - an optional number property of SpecialType with default {object} SpecialType1 - creates a new type named 'SpecialType' {number=} prop3 - an optional number property of SpecialType {{ prop1: string, prop2: string, prop3? There are various different ways to describe “object” parameters in JSDoc. The parameter type can be a built-in JavaScript type, such as If you provide a description, you can make the JSDoc comment more readable by inserting a hyphen Sign in to view. Be sure to include a space /*eslint valid-jsdoc: "error"*/ // expected @param tag for parameter num1 but found num instead // missing @param tag for parameter num2 // missing return type /** * Add two numbers. an additional If a parameter is destructured without an explicit name, you can give the object an appropriate one and

* Which means it works for stateless function components in JSX too * A parameter can be a class constructor, using Closure syntax.