是否有ESLINT规则可以为USESTATE执行类型()?
我想确保我们所有的团队成员都正确键入钩子。
const [users, setUsers] = useState<User>([]); // --> should work
const [users, setUsers] = useState([]); // --> should throw a linting error
到目前为止,我找不到这样的规则。如果没有现有插件,我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Eslint-Plugin-Require-exteric-generics
看起来像您想要的。https://www.npmjs.coms.coms.coms.coms.coms.coms.com/package/package/eslint-lint-plugin-require - 解释生成
到您传递要执行通用类型的函数的名称的选项(例如
usestate
或react.esext.usestate
)eslint-plugin-require-explicit-generics
looks like what you are looking for.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
orReact.useState
)