首页 > 解决方案 > 在 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

谢谢

标签: reactjstypescripteslintdestructuring

解决方案


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

享受!


推荐阅读