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

Prefer type literal over interface #4

Open
goodmind opened this issue Mar 16, 2017 · 5 comments
Open

Prefer type literal over interface #4

goodmind opened this issue Mar 16, 2017 · 5 comments
Labels
transferred to eslint port This issue has been transferred to github.com/jonaskello/eslint-plugin-ts-immutable

Comments

@goodmind
Copy link

This will be cool addition to https://github.com/jonaskello/tslint-immutable#no-mixed-interface or as standalone rule I think. Even better to allow functions only in interfaces and data only in type literals

@jonaskello
Copy link
Owner

jonaskello commented Mar 28, 2017

Thanks for the suggestion!

So if I understand correctly you want to disallow this:

interface Foo {
  readonly bar: number
}

and only allow:

type Foo = {
  readonly bar: number
}

Could you elaborate about the benefits of this?

My experience is that type aliases has some drawbacks for error reporting. When you use interface the errors usually include the interface name but for type aliases it prints the whole structure.

@goodmind
Copy link
Author

Oh, I think that your point is correct. But is no-mixed-interface works with type literals?

@jonaskello
Copy link
Owner

I think maybe we need an additional rule called no-mixed-types that mirrors what no-mixed-interfacedoes but for type declarations.

@jonaskello
Copy link
Owner

Actually I think there are two cases that are not covered:

  • Explicitly declaring mixed types with type.
  • Implicitly declaring mixed types via type literals.

@ghost
Copy link

ghost commented Nov 29, 2017

tslint-microsoft-contrib has the opposite of this: interface-over-type-literal

@RebeccaStevens RebeccaStevens added transferred to eslint port This issue has been transferred to github.com/jonaskello/eslint-plugin-ts-immutable and removed discussion labels Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transferred to eslint port This issue has been transferred to github.com/jonaskello/eslint-plugin-ts-immutable
Projects
None yet
Development

No branches or pull requests

3 participants