Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 918
Pawel Dobierski Avatar asked Sep 10 '14 19:09

Pawel Dobierski


1 Answers

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

like image 81
Tyler Avatar answered Oct 04 '22 15:10

Tyler