-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [unbound-method] Does not fail for destructured parameters #8947
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
Comments
To be clear, this is what you want to happen, right?: type HasMethod = { method(): void };
// actual
function f({ method }: HasMethod) {
}
// expected
function f({ method }: HasMethod) {
^^^^^^
} |
Yes, that destructured assignment should trigger the rule the same way as if it were destructured in the body. |
Awesome, thanks for the report! Seems like a bug to me as well. Looking at past work it looks like this was probably just a simple oversight when the code was added that handles other cases of destructuring (#2228). Might be as simple as adding |
I understand that it can be seen as a bug fix, but this is probably going to break many consumers who use the rule. For example, in my project, this is now flagged: import { expect, test } from '@playwright/experimental-ct-react';
import SomeComponent from './SomeComponent';
test('some component', async ({ mount }) => {
const result = await mount(<SomeComponent />);
// ...
}); Note that Playwright makes it mandatory to use destructuring here so the only escape hatch is to disable the rule in tests. It also affects React components with props defined like this: interface TestProps {
renderSomething(): string;
}
export function Test(props: TestProps) {
const { renderSomething } = props;
return <div>{renderSomething()}</div>
} In that second case, I could rewrite my interface to fix it: interface TestProps {
renderSomething: () => string;
} |
Do you have a link for that?
Indeed, that would be a more correct way to write that type. +1 that this is a bug fix. The |
I can't find a direct mention in the documentation, but this is part of the test fixtures feature. This is where they check for it. |
I'm with @JoshuaKGoldberg - the change is a correct bug fix. So this issue is correctly closed as completed. @targos Thanks for bringing this pain point up, though! Would you kindly spin off a new issue to continue the conversation? I think it merits discussion, so I wouldn't want this conversation to get buried by virtue of occurring in a closed issue. |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.4.3&fileType=.ts&code=MYGwhgzhAEAKD2ECWAXJ8B20DeBYAUNNAMQAe0AvNAAwDcBRxAnpTffg9KQBQCUO0TkQBOAUxQBXYVhQALJBAB0ZdkQC%2BBTkz44h0MZOnQ5C5U1XQN%2BKwQBmEjMDSZot%2BPG4AHAIwAuOIio6BgANAKk-qQATGFM-kxRlv4IyM4Y-HiE0MCYECjhkd6x8d6WrD4WBlJYANqk3joA1FxRfLEN-M0JfAC67FZAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6WJgIwHsOATWgFtE%2BABbc%2B6KImjRu0SODABfEMqA&tsconfig=&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
I expect the rule to fail when destructuring
x2
andy2
in the second function parameter.Actual Result
There are errors when destructuring
x1
andy1
in the function body as expected, but no error for the equivalent code within the function parameter.Additional Info
No response
The text was updated successfully, but these errors were encountered: