Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.23 KB

File metadata and controls

52 lines (40 loc) · 1.23 KB

1047 - A rest parameter cannot be optional.

🔍 Regex Patterns

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

💡 Suggestion

Remove question mark from rest parameter. Rest parameters cannot be optional - they are always optional by nature since they collect remaining arguments.

📝 Examples

Example 1: Optional rest parameter in function

- function testOptionalRest(...args?: string[]) {
+ function testOptionalRest(...args: string[]) {
    return args
  }

Explanation: Remove optional marker from rest parameter

Example 2: Optional rest parameter in arrow function

- const process = (...items?: number[]) => items
+ const process = (...items: number[]) => items

Explanation: Remove optional marker from rest parameter in arrow function

🖼️ Visual Output

Command

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

Result

docs/1047/index.ts:1:34 - error TS1047: A rest parameter cannot be optional.

1 function testOptionalRest(...args?: string[]) {
                                 ~

OR (without --pretty flag):

docs/1047/index.ts(1,34): error TS1047: A rest parameter cannot be optional.