Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.22 KB

File metadata and controls

54 lines (42 loc) · 1.22 KB

1020 - An index signature parameter cannot have an initializer.

🔍 Regex Patterns

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

💡 Suggestion

Remove initializer from index signature parameter. Index signature parameters cannot have default values.

📝 Examples

Example 1: Basic initializer in index signature

interface MyInterface {
-  [key: string = 'default']: any
+  [key: string]: any
}

Explanation: Index signature parameters cannot have default values, remove the initializer

Example 2: Different variable name and value

interface DataInterface {
-  [prop: string = 'value']: unknown
+  [prop: string]: unknown
}

Explanation: Remove default value from index signature parameter

🖼️ Visual Output

Command

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

Result

docs/1020/index.ts:2:4 - error TS1020: An index signature parameter cannot have an initializer.

2   [key: string = 'default']: any
     ~~~~~~~~~~~~~~~~~~~~~~~

OR (without --pretty flag):

docs/1020/index.ts(2,4): error TS1020: An index signature parameter cannot have an initializer.