Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 1.22 KB

File metadata and controls

58 lines (46 loc) · 1.22 KB

1019 - An index signature parameter cannot have a question mark.

🔍 Regex Patterns

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

💡 Suggestion

Remove question mark from index signature parameter. Index signature parameters cannot be optional.

📝 Examples

Example 1: Basic optional parameter in index signature

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

Explanation: Index signature parameters cannot be optional, remove the question mark

Example 2: Different variable name

- interface DataInterface {
-   [prop?: string]: unknown
- }
+ interface DataInterface {
+   [prop: string]: unknown
+ }

Explanation: Remove optional modifier from index signature parameter

🖼️ Visual Output

Command

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

Result

docs/1019/index.ts:2:7 - error TS1019: An index signature parameter cannot have a question mark.

2   [key?: string]: any
       ~

OR (without --pretty flag):

docs/1019/index.ts(2,7): error TS1019: An index signature parameter cannot have a question mark.