Skip to content

Add typedefs to no-use-before-define exceptions #6998

Closed
@sm-tc

Description

@sm-tc

Steps to Reproduce

type DispatchProps = typeof mapDispatch
type Props = DispatchProps

const Foo: React.FC<Props> = () => {}

const mapDispatch = {
  someWellTypedFn,
}

export default Foo

Expected Behavior

No lint errorrs; afaict this is a pretty common pattern in typescript/react projects and our codebase uses it pretty extensively

Actual Behavior

no-use-before-define complains about 'using' mapDispatch before it was defined.

The eslint config for no-use-before-define currently is

{
  ...
  'no-use-before-define': [
      'warn',
      {
        functions: false,
        classes: false,
        variables: false,
      },
    ],
  ...
}

I took a look at the typescript-eslint repo and it seems they allow an additional option typedefs which should take care of the issue. See here - the default value is true, but typedefs are hoisted like functions so there should be no danger setting it to false.

#6973 might fix the problem as well by allowing custom config, but IMO this should probably be something that just works ™️ out the box.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions