在 Typescript 的解构参数对象中查找未使用的属性

Find unused properties in destructured parameter object in Typescript

我们想检测(例如使用 ESlint 或 typescript)Typescript 中解构参数类型中未使用的属性,例如以下示例中的 "c"

const myIncompletelyRefactoredFunction = ({a, b}: {a: number, b: number, c: number}) => a + b

No-unused-var 允许我们检测以下情况:

//ts-error
const myIncompletelyRefactoredFunction = ({a, b, c}: {a: number, b: number, c: number}) => a + b 

但是在这种情况下重构还没有完成,这是我们想要检测的。

我们这里的用例是我们的 React 组件有几十个 props,其中类型仍然需要 props 尽管它们不再被使用

谢谢

有人在这里为您的用例提出了规则建议: https://github.com/typescript-eslint/typescript-eslint/issues/1529

尽情享受吧!