Skip to content

Files

Latest commit

 

History

History
39 lines (29 loc) · 865 Bytes

const-parameters.md

File metadata and controls

39 lines (29 loc) · 865 Bytes

Pattern: Reassigning constant parameter

Issue: -

Description

Disallows reassigning parameters that are considered constants.

Examples

function fn(/**@const*/foo, bar) {
  foo++; // error on this line
  bar++; // no error
}

class C {
  constructor(/** @const */ public foo) {
    foo++; // error on this line
    this.foo++; // no error on this line, because only parameters are checked by this rule
  }
}

function fn(/**@constant*/foo) { // also works with @constant tag
  foo++; // error on this line
}

function fn({ // also works with destructured parameters
  /**@const*/ foo,
  baz: /**@const*/ bar,
}) {
  foo++; // error on this line
  bar++; // error on this line
}

Further Reading