replace-in-file
replace-in-file copied to clipboard
Incorrect TypeScript definition for `ToCallback`
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()));