Skip to content

Latest commit

 

History

History
66 lines (51 loc) · 1.44 KB

File metadata and controls

66 lines (51 loc) · 1.44 KB

1052 - A 'set' accessor parameter cannot have an initializer.

🔍 Regex Patterns

regexFind: /set\s+([a-zA-Z_$][a-zA-Z0-9_$.-]*)\s*\(\s*([^=]+)\s*=\s*[^)]+\)/
regexReplace: set $1($2)

💡 Suggestion

Remove the parameter initializer from set accessor. Set accessors cannot have default values - they must have exactly one parameter without initialization.

📝 Examples

Example 1: Parameter with string initializer

  class TestClass {
    private _value: string = ''

-   set value(value: string = 'default') {
+   set value(value: string) {
      this._value = value
    }

    get value(): string {
      return this._value
    }
  }

Explanation: Remove parameter initializer from set accessor

Example 2: Parameter with number initializer

  class DataClass {
    private _count: number = 0

-   set count(count: number = 0) {
+   set count(count: number) {
      this._count = count
    }
  }

Explanation: Remove parameter initializer from set accessor with number type

🖼️ Visual Output

Command

npx tsc ./docs/1052/index.ts --noEmit --pretty

Result

docs/1052/index.ts:4:7 - error TS1052: A 'set' accessor parameter cannot have an initializer.

4   set value(value: string = 'default') {
        ~~~~~

OR (without --pretty flag):

docs/1052/index.ts(4,7): error TS1052: A 'set' accessor parameter cannot have an initializer.