ESLint reports no-undef error on flow-typed global types
Asked Answered
M

2

12

I have global types defined in /flow-typed/redux.flow.js :

declare type Action = {|
  +type: string,
  +payload: any,
|}

declare type State = {|
  +ui: UI,
  +user: User,
  +team: Team,
  +projects: Project[],
  +profile: Profile,
|}

declare type UI = {|
  +isSliderOpen: boolean,
  +isModalVisible: boolean,
  +modalAction: string,
  +modalPayload: Object,
|}

...

I have added airbnb eslint configuration to my project and now I get:

type Props = {
  logout: () => Action, //error ESLint 'Action' is not defined.(no-undef)
  user: UserDetails, //error ESLint 'UserDetails' is not defined.(no-undef)
}

Its purelly eslint fault. Everything is configured properly and flow by itself is happy.

How to tell eslint that these types are indeed declared as global? or should I add them to some ignore list?

Myers answered 13/7, 2017 at 19:8 Comment(0)
M
21

It turned out (like I thought) the way is not to add global types to eslint ignore list. Actually it's is all handled by eslint-plugin-flowtype which I already had installed but I didn't extend it like:

.eslintrc

"extends": ["airbnb", "plugin:flowtype/recommended"],
"plugins": [
  "flowtype"
],
Myers answered 15/7, 2017 at 16:11 Comment(0)
C
0

You can define global variables either using comments inside of a file, in the eslint configuration file or package.json. Read how to do it in eslint docs. If you need more help leave a comment.

Chalice answered 13/7, 2017 at 20:10 Comment(1)
Is this only solution? I would then have to have ignored every type from flow-typed directory like: SyntheticInputEvent or DispatchMyers

© 2022 - 2024 — McMap. All rights reserved.