Flow: "inconsistent use of library definitions"

Created on 11 Dec 2014  路  7Comments  路  Source: facebook/flow

For the code

destroy(id : string) {
      return promiseReturningFunction(id)
        .then(() => {
           // logic
        }, function(error) {
          // logic
        });
    },

I'm getting the following from flow:

/Users/tmcw/src/mapbox-gl-online/src/actions/actions.js: inconsistent use of library definitions
  /private/var/folders/lh/rwmhbvnd5rdc2qc5t5n2pv4w0000gn/T/flow_tmcw/flowlib_62a1d48/lib/core.js:296:1,305:1: Promise
This type is incompatible with
  /private/var/folders/lh/rwmhbvnd5rdc2qc5t5n2pv4w0000gn/T/flow_tmcw/flowlib_62a1d48/lib/core.js:298:25,52: function type

It's unclear what this error is trying to say, whether it's a problem in my code or with flow's internal definitions.

enhancement error messages

Most helpful comment

This is a known annoyance: basically this arises when, e.g., a result of lib function 1 in a user call is passed as an argument of lib function 2 in another user call, and the result and argument types are incompatible. The two end points are library functions, which get blamed instead of the two call sites in user code.

All 7 comments

This is a known annoyance: basically this arises when, e.g., a result of lib function 1 in a user call is passed as an argument of lib function 2 in another user call, and the result and argument types are incompatible. The two end points are library functions, which get blamed instead of the two call sites in user code.

Is there a workaround possible by annotating both calls?

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

Since this issue doesn't include runnable repro code, I can't confirm that this specific case is resolved, but I have tested a number of similar cases and found improvements. Please reply if you are still experiencing a bad error message and I'll reopen.

@samwgoldman: Here's a test case!

// @flow

const url = require('url');
url.format(url.parse('https://example.com/foo'));

and some outputs

test.js:0
inconsistent use of library definitions
1280:     href?: string;
                 ^^^^^^ undefined. This type is incompatible with. See lib: /tmp/flow/flowlib_cdecff4/node.js:1280
1277:     href: string;
                ^^^^^^ string. See lib: /tmp/flow/flowlib_cdecff4/node.js:1277

test.js:0
inconsistent use of library definitions
1285:     port?: string | number;
                          ^^^^^^ number. This type is incompatible with. See lib: /tmp/flow/flowlib_cdecff4/node.js:1285
1270:     port?: string;
                 ^^^^^^ string. See lib: /tmp/flow/flowlib_cdecff4/node.js:1270

/cc @avikchaudhuri

That error is expected, but it's easy to fix. I just put up a diff internally which will sync out soon.

Was this page helpful?
0 / 5 - 0 ratings