regexFind: /([a-zA-Z_$][a-zA-Z0-9_$]*)\?\s*:\s*([^=()]+?)\s*=\s*([^,)]+)/
regexReplace: $1: $2= $3Remove the question mark from optional parameters that have default values, or remove the default value from optional parameters
- function greet(name?: string = "Guest") {
+ function greet(name: string = "Guest") {
console.log(`Hello, ${name}!`)
}Explanation: Parameters with default values are automatically optional, so the '?' is redundant
- const greetArrow = (name?: string = "Guest") => {
+ const greetArrow = (name: string = "Guest") => {
console.log(`Hello, ${name}!`)
}Explanation: Arrow function parameters with default values don't need the '?'
npx tsc ./docs/1015/index.ts --noEmit --prettydocs/1015/index.ts:2:16 - error TS1015: Parameter cannot have question mark and initializer.
2 function greet(name?: string = "Guest") {
~~~~
docs/1015/index.ts:7:21 - error TS1015: Parameter cannot have question mark and initializer.
7 const greetArrow = (name?: string = "Guest") => {
~~~~OR (without --pretty flag):
docs/1015/index.ts(2,16): error TS1015: Parameter cannot have question mark and initializer.
docs/1015/index.ts(7,21): error TS1015: Parameter cannot have question mark and initializer.