使用JSDoc
/**基础类型*/ /**@type {string} */ /**联合类型 */ /**@type {string | number} */ /**数组类型 */ /**@type {string[]} */ /**@type {Array.<string>} */ /**对象字面量类型 */ /**@type {a:string,b:number} */ /**map-like 类型 */ /**@type {Object.<string,number>} */ /**array-like 类型 */ /**@type {Object.<number,object>} */ /**closure 语法 */ /**@type {function(string,boolean):number} */ /**TypeScript 语法 */ /**@type {(a:string,b:string) => number} */ /**函数类型 */ /**@type {function} */ /**任意类型 */ /**@type {*} */ /**@type {?} */ /**导入类型 */ /**@param {import('./a').Pet} */ /**@typedef Pet {import("./a").Pet} */ /**@type {Pet} */ /**params语法类似于type,唯一区别于可选属性 ,arg可选且默认值为test*/ /**@param [arg = 'test'] */ /**返回值类型 */ /**@return {string} */ /**复杂类型 */ /**@typedef {prop1:string,prop2:string,prop3?:number} SpecialType */ /**@typedef {(prop1:string,prop2?:number) => number} Predicate*/ /**泛型类型 */ /**@template T */ /**@param {T} */ /**@return {T} */ function id(x) {return x;} /**指定this的类型 */ /**@this {HTMLElement} */
/**基础类型*/
/**
@type
{string}
*/
/**联合类型 */
/**
@type
{string | number}
*/
/**数组类型 */
/**
@type
{string[]}
*/
/**
@type
{Array.<string>}
*/
/**对象字面量类型 */
/**
@type
{a:string,b:number}
*/
/**map-like 类型 */
/**
@type
{Object.<string,number>}
*/
/**array-like 类型 */
/**
@type
{Object.<number,object>}
*/
/**closure 语法 */
/**
@type
{function(string,boolean):number}
*/
/**TypeScript 语法 */
/**
@type
{(a:string,b:string) => number}
*/
/**函数类型 */
/**
@type
{function}
*/
/**任意类型 */
/**
@type
{*}
*/
/**
@type
{?}
*/
/**导入类型 */
/**
@param
{import('./a').Pet}
*/
/**
@typedef
Pet
{import("./a").Pet} */
/**
@type
{Pet}
*/
/**params语法类似于type,唯一区别于可选属性 ,arg可选且默认值为test*/
/**
@param
[arg = 'test'] */
/**返回值类型 */
/**
@return
{string}
*/
/**复杂类型 */
/**
@typedef
{prop1:string,prop2:string,prop3?:number}
SpecialType
*/
/**
@typedef
{(prop1:string,prop2?:number) => number}
Predicate
*/
/**泛型类型 */
/**
@template
T
*/
/**
@param
{T}
*/
/**
@return
{T}
*/
function
id(
x) {
return
x;}
/**指定this的类型 */
/**
@this
{HTMLElement}
*/
