Flow: Function cannot be called on any member of intersection type intersection

Created on 15 Dec 2016  路  4Comments  路  Source: facebook/flow

This debug statement is really vague and I've been trying to figure out why I keep getting these while using the reselect library.

export const getMaxSyncMin = createSelector(
  getNextThreadMeta,
  (meta: ThreadMetaContainer): ?number => {
    if (meta && meta.meta) return meta.meta.message_sync_min;
    return null;
  },
);

screen shot 2016-12-15 at 10 36 58 am

Most helpful comment

The message is indeed rather vague. Not only that, if you don't pay close attention it might even be misleading as it doesn't point to the exact culprit code line; it points to where the test execution failed instead.

Had a similar issue and took me a while to understand that this was about an Intersection Type that was being declared on the top of the file, while flow was pointing the error to the function call many lines later (same as your case).

For this specific case I'd figure that ThreadMetaContainer is an Intersection Type, e.g.:

type Type1 = { some: 'object' };
type Type2 = { something: 'else' };

type ThreadMetaContainer = Type1 & Type2;

Only way I manage to avoid this error was removing the intersection. Would love to know if there's any other a proper way to fix it.

All 4 comments

The message is indeed rather vague. Not only that, if you don't pay close attention it might even be misleading as it doesn't point to the exact culprit code line; it points to where the test execution failed instead.

Had a similar issue and took me a while to understand that this was about an Intersection Type that was being declared on the top of the file, while flow was pointing the error to the function call many lines later (same as your case).

For this specific case I'd figure that ThreadMetaContainer is an Intersection Type, e.g.:

type Type1 = { some: 'object' };
type Type2 = { something: 'else' };

type ThreadMetaContainer = Type1 & Type2;

Only way I manage to avoid this error was removing the intersection. Would love to know if there's any other a proper way to fix it.

export type ThreadMeta = {
  first: ?string,
  last: ?string,
  message_sync_min: number,
  message_sync_max: number,
  next: ?string,
  previous: ?string,
};

export type ThreadMetaContainer = {
  mailboxId: string,
  folderId: string,
  meta: ThreadMeta,
};

My guess is it is something internal to the flow-typed reselect library that is causing the issue.

https://github.com/flowtype/flow-typed/blob/master/definitions/npm/reselect_v3.x.x/flow_v0.37.x-/reselect_v3.x.x.js

It's really unfortunate but my solution was to remove the libdef for reselect altogether.

@neurosnap would you be willing to test out this version of the reselect type definition? It is basically a conversion of the typescript typings from reselect repository.
Should work for flow 0.54 and above https://github.com/thehogfather/flow-typed/blob/master/definitions/npm/reselect_v3.x.x/flow_v0.54.x-/reselect_v3.x.x.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glenjamin picture glenjamin  路  3Comments

philikon picture philikon  路  3Comments

cubika picture cubika  路  3Comments

pelotom picture pelotom  路  3Comments

funtaps picture funtaps  路  3Comments