flowtype

Missing-this-annot together with jQuery each()


Pretty basic usage of jQuery that seems not easy to give a proper type in Flow inline?

jQuery(`.someclass`).each(function(j, el) { ... }

Any tips? I've tried to add /*this: Object*/ or such, but seems not enough. Obviously I cannot change the order of arguments in an external library function like this, even tho Flow wants this to always be the first argument.

I already have declare var jQuery: any at top of file, btw. Do I need to be more specific?


Solution

  • Have you tried leveraging flow-typed? jquery is already typed there and seems the each function you're looking for is also there https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/jquery_v3.x.x/flow_v0.104.x-/jquery_v3.x.x.js#L3257