eslint-plugin-import how to add flow declared modules to exceptions

1k views Asked by At

I have a file in flow-typed directory with some common type declarations like:

common-types.js

// @flow

declare module 'common-types' {
  declare export type RequestState = {
    setLoading: () => void,
    setFinished: () => void,
    setError: (error: AxiosFailure) => void,
    reset: () => void,
    status: LoadingStatus,
    error: AxiosFailure | void,
  };

  declare export type LoadingStatus = '' | 'loading' | 'finished';

  declare export type ErrorObject = { [key: string]: string | string[] | Error };

  declare export type AxiosFailure = {
    status: number,
    data: ErrorObject,
  }

}

Now I import it like this in files:

import type { RequestState } from 'common-types';

but I get eslint-plugin-import errors about missing file extension as well as unable to resolve path to module 'common-types'

How do I deal with it?

1

There are 1 answers

2
Tomasz Mularczyk On

I found a solution. As @logansmyth suggested in comment

Your types should just pass your code along with your data

The problem I had was with webpack aliases. Flow pointed me errors about modules not being installed. Hovewer I found out that I can use mappers in .flowconfig like:

module.name_mapper='^common' ->'<PROJECT_ROOT>/src/common'

along with webpack aliases, which makes eslint-plugin-import and flow happy as well properly type-checking. Now I import types along with common components, no messing with flow-typed directory.