regexFind: /set\s+([a-zA-Z_$][a-zA-Z0-9_$.-]*)\s*\(\s*([^)]*)\?([^)]*)\)/
regexReplace: set $1($2$3)Remove the optional parameter modifier (?) from set accessor. Set accessors cannot have optional parameters - they must have exactly one required parameter.
class TestClass {
private _value: string = ''
- set value(value?: string) {
+ set value(value: string) {
this._value = value || 'default'
}
get value(): string {
return this._value
}
}Explanation: Remove optional parameter modifier from set accessor
class DataClass {
private _config: any
- set config(item?: any) {
+ set config(item: any) {
this._config = item
}
}Explanation: Remove optional parameter modifier from set accessor with type annotation
npx tsc ./docs/1051/index.ts --noEmit --prettydocs/1051/index.ts:4:18 - error TS1051: A 'set' accessor cannot have an optional parameter.
4 set value(value?: string) {
~OR (without --pretty flag):
docs/1051/index.ts(4,18): error TS1051: A 'set' accessor cannot have an optional parameter.