Skip to content Skip to sidebar Skip to footer

Assignment To Property Of Function Parameter (no-param-reassign)

I have this function and while I have this working nicely, I'm getting ESLint error saying 57:5 error Assignment to property of function parameter 'result' no-param-reassign

Solution 1:

This is a common ESLint issue that appears frequently on old codebase. You have modified the result variable which was passed as parameter. This behavior is prohibited by the rule.

To resolve it, copy the argument to a temporary variable and work on it instead:

exportconstfn = article => article.categoryValueDtoSet.reduce((res, item) => {
    const result = {...res}; // if result is object// const result = [...res]; // if result is array// Rest of your code can work without change
}

Note: The object spread operator is sugar syntax for Object.assign(). Both it and the array copy is not deep here for simplicity sake and could cause side effects because you are still accessing the original individual elements of the source object or array. Prefer to use a deep copy instead.

Post a Comment for "Assignment To Property Of Function Parameter (no-param-reassign)"