Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-misused-promises] check contextual type#10042

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 4 commits intotypescript-eslint:mainfromyeonjuan:fix/8054
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletionspackages/eslint-plugin/src/rules/no-misused-promises.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -743,6 +743,20 @@ function checkThenableOrVoidArgument(
) {
voidReturnIndices.add(index);
}
const contextualType = checker.getContextualTypeForArgumentAtIndex(
node,
index,
);
if (contextualType !== type) {
checkThenableOrVoidArgument(
checker,
node,
contextualType,
index,
thenableReturnIndices,
voidReturnIndices,
);
}
}

// Get the positions of arguments which are void functions (and not also
Expand Down
107 changes: 107 additions & 0 deletionspackages/eslint-plugin/tests/rules/no-misused-promises.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1051,6 +1051,21 @@ interface MyInterface extends MyCall, MyIndex, MyConstruct, MyMethods {
const array: number[] = [1, 2, 3];
array.filter(a => a > 1);
`,
`
type ReturnsPromiseVoid = () => Promise<void>;
declare const useCallback: <T extends (...args: unknown[]) => unknown>(
fn: T,
) => T;
useCallback<ReturnsPromiseVoid>(async () => {});
`,
`
type ReturnsVoid = () => void;
type ReturnsPromiseVoid = () => Promise<void>;
declare const useCallback: <T extends (...args: unknown[]) => unknown>(
fn: T,
) => T;
useCallback<ReturnsVoid | ReturnsPromiseVoid>(async () => {});
`,
],

invalid: [
Expand DownExpand Up@@ -2322,5 +2337,97 @@ tuple.find(() => Promise.resolve(false));
},
],
},
{
code: `
type ReturnsVoid = () => void;
declare const useCallback: <T extends (...args: unknown[]) => unknown>(
fn: T,
) => T;
declare const useCallbackReturningVoid: typeof useCallback<ReturnsVoid>;
useCallbackReturningVoid(async () => {});
`,
errors: [
{
line: 7,
messageId: 'voidReturnArgument',
},
],
},
{
code: `
type ReturnsVoid = () => void;
declare const useCallback: <T extends (...args: unknown[]) => unknown>(
fn: T,
) => T;
useCallback<ReturnsVoid>(async () => {});
`,
errors: [
{
line: 6,
messageId: 'voidReturnArgument',
},
],
},
{
code: `
interface Foo<T> {
(callback: () => T): void;
(callback: () => number): void;
}
declare const foo: Foo<void>;

foo(async () => {});
`,
errors: [
{
line: 8,
messageId: 'voidReturnArgument',
},
],
},
{
code: `
declare function tupleFn<T extends (...args: unknown[]) => unknown>(
...fns: [T, string, T]
): void;
tupleFn<() => void>(
async () => {},
'foo',
async () => {},
);
`,
errors: [
{
line: 6,
messageId: 'voidReturnArgument',
},
{
line: 8,
messageId: 'voidReturnArgument',
},
],
},
{
code: `
declare function arrayFn<T extends (...args: unknown[]) => unknown>(
...fns: (T | string)[]
): void;
arrayFn<() => void>(
async () => {},
'foo',
async () => {},
);
`,
errors: [
{
line: 6,
messageId: 'voidReturnArgument',
},
{
line: 8,
messageId: 'voidReturnArgument',
},
],
},
],
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp