Option to force the type when using JSdoc

92 views
Skip to first unread message

Paul

unread,
Nov 25, 2014, 4:16:36 PM11/25/14
to tern...@googlegroups.com
Hi,

I was wondering if there's an option to force the type if the type is specified by JSDoc. For example, if I have the code below, I'd expect only codecompletion on the number type
/**
 * @returns{Number}
 */
function test(){
  returns 'hello'
}

According to me, when JSDoc specifies something, that should be leading and additional types retrieved through inference should be ignored.

Ideally, a validator (tern.lint for example) would raise an error here that the function returns a value that is not of the type declared in the JSDoc

If this is not yet available, could this be (easily) added?

TIa,

Paul

Marijn Haverbeke

unread,
Dec 4, 2014, 6:04:37 AM12/4/14
to Paul, tern-dev
I don't think this should be the default behavior, but patch
https://github.com/marijnh/tern/commit/8f485d5577b8aca60ccef01225f41fa5b252100a
implements this as an optional setting. If you configure the
doc_comment plugin with strong: true in your .tern-project file, it'll
assign a higher-than-default weight to the types it finds in comments,
and thus overrides inferred types.

Does this work for you?
> --
> You received this message because you are subscribed to the Google Groups
> "tern-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tern-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages