Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.08 KB

File metadata and controls

54 lines (42 loc) · 1.08 KB

1021 - An index signature must have a type annotation.

🔍 Regex Patterns

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

💡 Suggestion

Add a type annotation to the index signature. Index signatures must specify the type of their values.

📝 Examples

Example 1: Basic index signature missing type annotation

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

Explanation: Add type annotation to index signature

Example 2: Different variable name

+ interface DataInterface {
-  [prop: string]
+  [prop: string]: any
+ }

Explanation: Index signatures must have a type annotation for their values

🖼️ Visual Output

Command

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

Result

docs/1021/index.ts:2:3 - error TS1021: An index signature must have a type annotation.

2   [key: string]
    ~~~~~~~~~~~~~

OR (without --pretty flag):

docs/1021/index.ts(2,3): error TS1021: An index signature must have a type annotation.