Skip to content

import flow type from index.js.flow file: #616

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
rkurbatov opened this issue Oct 7, 2016 · 10 comments
Closed

import flow type from index.js.flow file: #616

rkurbatov opened this issue Oct 7, 2016 · 10 comments

Comments

@rkurbatov
Copy link

rkurbatov commented Oct 7, 2016

When I do import type MyType from '.' flow itself correctly assumes that file index.js.flow should be used, but eslint plugin searches for index.js first and only then for index.js.flow. For other filenames, this works normally. For my case, I should use import type Type from './index.js.flow', that is quite verbose. Otherwise, I get Unable to resolve path to module '.' import/no-unresolved error

@jfmengels
Copy link
Collaborator

I don't know how much we are willing to support Flow. I started using it recently (and really like it), so I'm all for supporting it, especially as we already have some rules that handle Flow differently. I don't know how @benmosher feels about this though.

That said, this might be a better fit for a custom resolver (see https://github.com/tleunen/eslint-import-resolver-babel-module for instance).

Either way, it would be nice to have docs on how this gets resolved. cc @thejameskyle.

@jamiebuilds
Copy link

Would it not make sense to try .js.flow when you see import type since you already support that?

@jfmengels
Copy link
Collaborator

That sounds good to me. Are there any other files that you attempt to resolve it to when foo.js.flow is not found (except for foo.js? I just want to be clear on the resolver logic.

@rkurbatov
Copy link
Author

rkurbatov commented Oct 10, 2016

@jfmengels seems not for me. And don't forget about specific '.' or '/' case for 'index.js' - 'index.js.flow' case, please.

@benmosher
Copy link
Member

This could be handled by configuring the Node resolver with ['.js', '.js.flow'] as its extensions, see https://www.npmjs.com/package/eslint-import-resolver-node for config example.

@benmosher
Copy link
Member

benmosher commented Nov 3, 2016

Actually, maybe this would be best handled with a Flow-based shared config, like the existing React, Electron, etc. ones, example https://github.com/benmosher/eslint-plugin-import/blob/master/config/react-native.js

@SpainTrain
Copy link

Is this issue still relevant? If not let me know and I will open a new issue for my specific problem.

Related to example provided by OP, it is also not possible to import types that are exported by an npm module in a natural way. For example, this works with flow but results in named error from eslint-plugin-import

import type {FormProps} from 'redux-form'

but this works and results in no eslint error

import type {FormProps} from 'redux-form/es/index.js.flow'

@rkurbatov
Copy link
Author

rkurbatov commented Sep 14, 2017

It's working, at least in 2.3.0. I mean my initial import type { X } from '.' case. Though we've agreed to put all type definitions in types.js files everywhere.

import type { FormProps } from 'redux-form' may be overridden by flow-typed library definitions, f.e. if we use import type { Connector } from 'react-redux' it's taken from flow-typed/react-redux_v5.x.x file.

@SpainTrain
Copy link

SpainTrain commented Sep 14, 2017

Thanks for the update.

I don't think that is our particular issue - we don't have redux-form in our flow-typed directory.

I will open a new issue since it sounds like this one is for a different, resolved problem.

EDIT: opened as #927

@soryy708
Copy link
Collaborator

I'm closing this one due to inactivity, and looks like the problem is resolved?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

6 participants