-
-
Notifications
You must be signed in to change notification settings - Fork 33
Description
This is a follow up to @RebeccaStevens' #153 which described the issue very well:
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).
That issue was mostly solved (and marked as solved) by #480, but as far as I can tell, there isn't yet a way to enforce mutable return types with the new prefer-immutable-types rule.
Maybe a solution could add a "Mutable" option to the available settings for returnTypes.enforcement?
type Options = {
// ...
returnTypes?: {
enforcement: "Mutable" | "None" | "ReadonlyShallow" | "ReadonlyDeep" | "Immutable";
ignoreInferredTypes: boolean;
ignoreClasses: boolean | "fieldsOnly";
ignoreNamePattern?: string[] | string;
ignoreTypePattern?: string[] | string;
};
// ...
};Am I missing another way in which this feature was added? Thanks!