Flowtype: How to properly use $ObjMap for making all functions chainable?

I’m working on some JS package and I want to provide separated flow type definitions as index.js.flow because internal behavior is slightly different.

I have this function for create component definition

function defineComponent(name, createFunc); 

createFunc is function which grabs elements and returns object containing particular user defined actions upon that component

so you can call defineComponent in this manner:

const loginForm = defineComponent("login form", () => {   ...   ...   return {     fillUsername: () => { ...doesn't matter what is return type... },     fillPassword: () => { ...doesn't matter what is return type... }   }; }); 

and those actions should be chainable, but I don’t want to burden user with always mentioning return type within each user defined action. So final chain should look like this:

loginForm   .fillUsername()   .fillPassword(). 

So internally defineComponent will wrap each user defined action like this:

function defineComponent(..., createFunc) {   const actions = createFunc(...);    return actions.map(action => {     return (...args) => {       action(...args);       return actions;     }   }) } 

I already tried this (my whole testing code):

type ComponentType<T> = $  ObjMap<T, <V>((V) => any) => V => ComponentType<T>>;  declare function defineComponent<T>(   name: string,   createFunc: () => T ): ComponentType<T>;  const Component = defineComponent("foo", () => {   return {     fooAction: () => {},     barAction: () => {}   }; });  Component.fooAction().barAction() 

I proceeds with flow’s No errors! but flow is showing no errors also when I do something like


And also VS Code provides no autocompletion above that :/