Mobx-state-tree: [TypeScript] Invalid overload type when using `flow()`

Created on 2 Nov 2017  路  7Comments  路  Source: mobxjs/mobx-state-tree

const fetch = flow(function *(url: string, options: RequestInit = {}) {
...
});

const create = (url: string, data: {}) => {
  return fetch(url, {
    body: JSON.stringify(data),
    method: 'POST',
  });
};

// [ts] Expected 1 arguments, but got 2.
// const fetch: (a1: string) => Promise<any>
Typescript breaking change bug has PR

Most helpful comment

Got similar problem in flow(f) then I use an optional argument, fixed by removing ?...

loadM: flow(function* loadM(forceReload?: boolean) {
    TS2554: Expected 0 arguments, but got 1.

All 7 comments

Unfortunately known TS issue of not having variadic types :/

Got similar problem in flow(f) then I use an optional argument, fixed by removing ?...

loadM: flow(function* loadM(forceReload?: boolean) {
    TS2554: Expected 0 arguments, but got 1.

Closing until variadic types :'(

Any workaround?

Reopening since now it has a PR

Any workaround?

You can declare "type" for arguments, example:


type Filter = {
   id?: number
   owner?: number
}
function* findOne(filter: Filter) {
   ...
}

Closing, a fix was released with mst 3.9

Was this page helpful?
0 / 5 - 0 ratings