Flow: Error "inconsistent use of library definitions" does not show actual source line

Created on 23 Oct 2016  路  3Comments  路  Source: facebook/flow

The following example shows an instance of the "inconsistent use of library definitions" error without correctly identifying the actual source of the problem. Only using flow check --traces 10 as suggested by @gabelevi in https://github.com/facebook/flow/issues/2671 allowed me to track down the problem.

error:

src/main.js:0
inconsistent use of library definitions
  2:    data: Array<string>
                    ^^^^^^ string. This type is incompatible with. See lib: src/main.js.flow:2
  6:    config: {names: Array<{id: string}>}
                              ^^^^^^^^^^^^ object type. See lib: src/main.js.flow:6

src/main.js:0
inconsistent use of library definitions
  6:    config: {names: Array<{id: string}>}
                              ^^^^^^^^^^^^ object type. This type is incompatible with. See lib: src/main.js.flow:6
  2:    data: Array<string>
                    ^^^^^^ string. See lib: src/main.js.flow:2

main.js

// @flow
import {sub} from './sub';
function main(obj: objectType) {
    sub({data: obj.config.names});
}

sub.js

// @flow
export function sub(data: dataType) {}

main.js.flow

type dataType = {data: Array<string>};
declare class objectType {config: {names: Array<{id: string}>}}

I would be great, if flow could:

  • point to the actual source problem in main.js at line 4
  • add a list of possible errors and possible solutions in it's documentation (like the --traces hint)
error messages

Most helpful comment

thanks, will see what I can do to reposition this better. I think this is a general problem with the way Flow errors on nested types (polymorphic types in this case, since it's Array<T>).

the error should say that the entire array is incompatible with the required array type. that would let it error in main.js like you suggested.

All 3 comments

thanks, will see what I can do to reposition this better. I think this is a general problem with the way Flow errors on nested types (polymorphic types in this case, since it's Array<T>).

the error should say that the entire array is incompatible with the required array type. that would let it error in main.js like you suggested.

after updating 0.46.0 i am getting this error. i have an idea that it's related to some use of polymorphic types in the file, but since it gives me no info I have no idea how to fix it

it feels like a poor use of time to me to spend all day chasing this bug, so I downgraded to 0.43.1, which is the last version that does not throw this error, if that helps in any way

I wasn't able to repro (objectType and dataType are undefined), but we've made improvements to error localization which should resolve cases like this. Please reopen if you still get a bad error message on this code.

Was this page helpful?
0 / 5 - 0 ratings