Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

import/prefer-default-export should ignore type for flowtype #484

Closed
justin808 opened this issue Aug 12, 2016 · 4 comments · Fixed by #639
Closed

import/prefer-default-export should ignore type for flowtype #484

justin808 opened this issue Aug 12, 2016 · 4 comments · Fixed by #639

Comments

@justin808
Copy link

justin808 commented Aug 12, 2016

I have a file with this:

// @flow
export type CommentType = {
  mobile_image_thumbnail: string,
  author_name: string,
  preview_text: string,
  updated_at: string,
}

I get this error:

app/bundles/comments/types/index.js
2:1 error Prefer default export import/prefer-default-export

See doc note:

Note that we only support the explicit named-export statements for now (i.e. export type UserID = number;). In a future version we can add support for latent named-export statements (i.e. type UserID = number; export {UserID};) and default type exports (i.e. export default type MyType = ... ;)…but for now these forms aren’t yet supported for type exports.

I just checked and export default type is not supported in 0.27.

Any chance of ignoring export type as an option to this rule?

@benmosher
Copy link
Member

Yeah, that should be fine.

Would love someone with Flow experience to submit a PR, I'm not familiar enough with it to confidently work this in.

@justin808
Copy link
Author

@benmosher I don't think you need flow experience. Just ignore export type from the rule. I guess there's the edge case when you want export type to be recognized, in case you name a variable or function type. How about an option for the rule if export type should be ignored?

Or maybe a regexp to ignore?

jakubsta added a commit to jakubsta/eslint-plugin-import that referenced this issue Oct 24, 2016
benmosher pushed a commit that referenced this issue Nov 3, 2016
* Ignoring flow type exports, resolve #484

* Added test and note to CHANGELOG
@rodrigobdz
Copy link
Contributor

The following file is generating a warning that default export should be used.

Prefer default export. (import/prefer-default-export)

/* @flow */

export type AnswerState = {
  foo: string
}

export const answer: AnswerState = {
  foo: ''
}

This one however, is not generating any errors or warnings.

/* @flow */

- export type AnswerState = {
+ type AnswerState = {
  foo: string
}

export const answer: AnswerState = {
  foo: ''
}

+ export type { AnswerState }

Shouldn't it be consistent?

@ljharb
Copy link
Member

ljharb commented Aug 23, 2018

Yes; please file a new issue for that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants