8000 [prefer-readonly-type] Rework this rule. · Issue #153 · eslint-functional/eslint-plugin-functional · GitHub
[go: up one dir, main page]

Skip to content
[prefer-readonly-type] Rework this rule. #153
Closed
@RebeccaStevens

Description

@RebeccaStevens

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeThis change will require a new major release.Feature RemovalA feature is no longer wanted/needed (remove/deprecate it)Status: In ProgressIssue is currently being resolved by a developer.Type: EnhancementEnhancement of the code, not introducing new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0