是否可以通过 eslint 强制执行以下规则?
- 如果函数参数的数量超过一个,则使用“object”作为参数。
例如,
- 好
- const f = (x: 字符串) => ...
- const f = (x: {id: string}) => ...
- const f = (x: {id: string; name: string}) => ...
- 不好
- const f= (x: 字符串; y: 字符串) => ...
我查看了官方文档( https://eslint.org/docs/rules/ ),但没有找到合适的规则。 我想知道是否某种自定义规则可以实现这一点。
最佳答案
您可以使用max-params
规则。 https://eslint.org/docs/rules/max-params将 max
值设置为 1
。
关于javascript/typescript - 强制通过 eslint 规则将对象作为函数参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70873945/