Babel-eslint: Reports Flow types for function parameters with default values as unused.

Created on 17 Sep 2015  路  5Comments  路  Source: babel/babel-eslint

When using Flow, most type annotations work perfectly. However, a custom type that is only used as a type declaration for a function parameter with a default value is reported as being unused. Here's a simple example:

type ResolveOptionType = {
  depth?: number,
  identifier?: string
};

function resolve(
  root: Object,
  options: ResolveOptionType = {}
): Object { /* ... */ }

Reports the following error: error "ResolveOptionType" is defined but never used no-unused-vars. If this is a limitation of Flow, not babel-eslint, please let me know so I can put my issue in the right place.

bug

Most helpful comment

Ok I fixed it as well.

All 5 comments

Pretty sure it's not a limitation of flow.

It might be similar to an known issue I put in the readme? Have to look into it more

  • no-unused-vars/no-undef with Flow declarations (declare module A {}) #132

Ok I guess it's a bug since options: ResolveOptionType by itself works.

However a workaround is to do options = {} : ResolveOptionType instead of options : ResolveOptionType = {}.

Ok I fixed it as well.

Fabulous, thank you very much. The proposed workaround throws an error in Flow, so the solution is great!

Was this page helpful?
0 / 5 - 0 ratings