gajus / gajus/eslint-plugin-flowtype

tricky behaviour of `define-flow-type` rule

Open
#508 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
1.1k
Forks
151
PR merge metrics
No merged PRs in 30d

Description

Hi there! I found some tricky behaviour with `define-flow-type` rule:
```ts
type A = {foo: Foo};
Foo();
```
`no-undef` with `define-flow-type` rules will not pay attention to `Foo` variable. It starts to be global. Yeah, Flow checks it, but see real code that cause of issue:
```ts
type Props = {children: React.Node};

export default React.memo(({ children }: Props) => children)
```
Flow and eslint were not give the error. But in runtime error was thrown "React is not defined" because it does have react import.

I suggest making the option for this rule like `ignoreTypes`. It will be array with all types that will not were global.

What do you think about it? Thanks!

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the examples involving the `define-flow-type` and `no-undef` rules, especially the unimported `React` reference. Trace how `define-flow-type` makes names from Flow annotations global, then add coverage for the proposed `ignoreTypes` behavior and verify that runtime-used names still produce `no-undef` errors when they are not imported.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.