Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): Skip missing 'rest' tuple type arguments in no-misused-promises #5809

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/eslint-plugin/src/rules/no-misused-promises.ts
Expand Up @@ -564,7 +564,11 @@ function voidFunctionArguments(
// Check each type in the tuple - for example, [boolean, () => void] would
// add the index of the second tuple parameter to 'voidReturnIndices'
const typeArgs = checker.getTypeArguments(type);
for (let i = index; i < node.arguments.length; i++) {
for (
let i = index;
i < node.arguments.length && i - index < typeArgs.length;
i++
) {
checkThenableOrVoidArgument(
checker,
node,
Expand Down
19 changes: 19 additions & 0 deletions packages/eslint-plugin/tests/rules/no-misused-promises.test.ts
Expand Up @@ -419,6 +419,14 @@ new TakeCallbacks(
() => true,
);
`,
`
function restTuple(...args: []): void;
function restTuple(...args: [string]): void;
function restTuple(..._args: string[]): void {}

restTuple();
restTuple('Hello');
`,
],

invalid: [
Expand Down Expand Up @@ -1099,5 +1107,16 @@ new TakesVoidCb(
`,
errors: [{ line: 11, messageId: 'voidReturnArgument' }],
},
{
code: `
function restTuple(...args: []): void;
function restTuple(...args: [boolean, () => void]): void;
function restTuple(..._args: any[]): void {}

restTuple();
restTuple(true, () => Promise.resolve(1));
`,
errors: [{ line: 7, messageId: 'voidReturnArgument' }],
},
],
});