23

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.

1
  • 2
    I think the = modifier is only valid for function parameters, not for record type properties. Commented Sep 10, 2014 at 19:17

1 Answer 1

27

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

Sign up to request clarification or add additional context in comments.

2 Comments

Instead of |undefined shouldn't it be title?:string?
Not for Closure Compiler, no.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.