function a(arg1: string, arg2?: number) {
}
function b(callback: (arg1: string, arg2?: string) => void) {
}
b((arg1) => a(arg1)); // rule warns on this...
b(a); // ...but this isn't valid
with tslint.json configuration:
"no-unnecessary-callback-wrapper": true
If the 2nd args are optional and different types, the rule flags this, but it can't be fixed by unwrapping
Shouldn't warn, but I don't think this can be fixed without type checking
The classic example of this is map and parseInt:
> ['010', '010', '010'].map(x => parseInt(x))
[10, 10, 10]
> ['010', '010', '010'].map(parseInt)
[10, NaN, 2]
Same problem


This rule breaks several window methods, for example:
const foo = {
bar: (cb) => setTimeout(cb)
}
which becomes
const foo = {
bar: setTimeout
}
And foo.bar() throws TypeError: illegal invocation.
This thing happens with all window methods like setTimeout, clearTimeout, etc.
I made a small reproducement repo for a simplified case of something we ran into in our code.
await new Promise<void>(res => {
document.addEventListener('click', () => res());
});
Replacing () => res() with res results in a Typescript error (Event and void is not compatible for the Promise).
https://github.com/csvn/tslint-issue-no-unnecessary-callback-wrapper
Is there a workaround for this issue?
TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โ
๐ It was a pleasure open sourcing with you!
๐ค Beep boop! ๐ TSLint is deprecated ๐ _(#4534)_ and you should switch to typescript-eslint! ๐ค
๐ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐
Most helpful comment
This rule breaks several window methods, for example:
which becomes
And
foo.bar()throwsTypeError: illegal invocation.This thing happens with all window methods like
setTimeout,clearTimeout, etc.