adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

Incorrect TypeScript definition for `ToCallback` #123

Closed smithki closed 1 year ago

smithki commented 4 years ago

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()));
roydukkey commented 9 months ago

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()));

I believe this was incorrectly closed. Whatever method was believed to have completed this PR, still doesn't satisfy all the possibilities.