Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 1.2 KB

File metadata and controls

58 lines (46 loc) · 1.2 KB

1024 - 'readonly' modifier can only appear on a property declaration or index signature.

🔍 Regex Patterns

regexFind: /readonly\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/
regexReplace: $1(

💡 Suggestion

Remove 'readonly' modifier from method declaration. The 'readonly' modifier can only be used on properties and index signatures.

📝 Examples

Example 1: Readonly modifier on method

class MyClass {
-  readonly method() {
+  method() {
     return 'test'
   }
}

Explanation: Remove readonly modifier from method declaration

Example 2: Different method name

class DataClass {
-  readonly process() {
+  process() {
     return 'data'
   }
}

Explanation: Readonly modifier cannot be used on methods

🖼️ Visual Output

Command

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

Result

docs/1024/index.ts:2:3 - error TS1024: 'readonly' modifier can only appear on a property declaration or index signature.

2   readonly method() {
    ~~~~~~~~

OR (without --pretty flag):

docs/1024/index.ts(2,3): error TS1024: 'readonly' modifier can only appear on a property declaration or index signature.