Description
Function Return Types
The return type of functions shouldn't be enforced to be immutable (by default) (this behavior can currently be turned on with the allowMutableReturnType
option).
Following from this, the rule @typescript-eslint/explicit-function-return-type
should no longer be a recommend external rule.
Enforce Mutable Return Types
If the return type has to immutable then something very non-functional is going on. What happens to the data after it is returned by a function should be of no concern to the function itself. Mutable return types are more compatible with 3rd-party non-function code as readonly types can not be given as mutable types in TypeScript (while mutable types can be given as either a mutable or readonly type).
An option to enforce this behaviour should be added to the rule (whether this is the default behavior or not is currently undecided).
Type Aliases
Often a mutable type needs to be aliased. This rule should not trigger an error when a mutable type is aliased (by default), only when the mutable type is used.
Care will be need to be taken when implementing this to keep performance good - we don't want to reevaluate every instance of type alias usage to check whether it's mutable or not.
New Rule
As this is such a large change to the current implementation of rule, it's probably best to instead create this change as a new rule and deprecate the current rule. Any suggestions on a new rule name?