tslint-immutable
tslint-immutable copied to clipboard
Prefer type literal over interface
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
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.
Oh, I think that your point is correct. But is no-mixed-interface works with type literals?
I think maybe we need an additional rule called no-mixed-types that mirrors what no-mixed-interfacedoes but for type declarations.
Actually I think there are two cases that are not covered:
- Explicitly declaring mixed types with
type. - Implicitly declaring mixed types via type literals.
tslint-microsoft-contrib has the opposite of this: interface-over-type-literal