replace-in-file icon indicating copy to clipboard operation
replace-in-file copied to clipboard

Incorrect TypeScript definition for `ToCallback`

Open smithki opened this issue 5 years ago • 0 comments

The ToCallback type definition indicates the second argument should be string, but actually the function takes the same shape as a String.prototype.replace replacer.

Unfortunately, there's not a surefire way to type a replacer as it's not statically analyzable. Instead of passing all arguments to the ToCallback function, it would be more sound (in my opinion), to do something like this:

contents.replace(item, (...args) => replacement(args[0], args.pop()));

smithki avatar Jul 15 '20 19:07 smithki