简体   繁体   中英

How to annotate anonymous object with optional property in JSDoc

I have a JavaScript class that takes one argument of type Object with defined set of properties and the Closure Compiler is happy when I annotate it like:

@constructor
@param {{ subview:BaseView, el:(jQuery|Element), title:String }} options
var MyView = function(options){ }

I would like to make title key optional and pass title value to some instances of my class and implement fallback behavior when this key is not present, so I annotated my class with:

@constructor
@param {{ subview:BaseView, el:(jQuery|Element), title:String= }} options
var MyView = function(options){ }

and now Closure Compiler is complaining:

WARNING - Bad type annotation. expected closing }

I've checked Annotating JavaScript for the Closure Compiler , but I see no single line describing such use case.

@param {{ subview:BaseView, el:(jQuery|Element), title:(string|undefined) }} options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM