[英]Is there an eslint rule to enforce types for useState()?
I would like to make sure that all our team members properly type their hooks.我想确保我们所有的团队成员都正确地输入了他们的钩子。
const [users, setUsers] = useState<User>([]); // --> should work
const [users, setUsers] = useState([]); // --> should throw a linting error
So far I couldn't find such a rule.到目前为止,我找不到这样的规则。 How could I do it myself if there is no existing plugin?
如果没有现成的插件,我怎么能自己做呢?
eslint-plugin-require-explicit-generics
looks like what you are looking for. eslint-plugin-require-explicit-generics
看起来像您正在寻找的东西。
https://www.npmjs.com/package/eslint-plugin-require-explicit-generics https://www.npmjs.com/package/eslint-plugin-require-explicit-generics
to the options you pass name of the functions that you want the generic type to be enforced (eg. useState
or React.useState
)传递给您希望强制执行通用类型的函数名称的选项(例如
useState
或React.useState
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.