是否有ESLINT规则可以为USESTATE执行类型()?

发布于 2025-01-22 21:05:14 字数 245 浏览 2 评论 0原文

我想确保我们所有的团队成员都正确键入钩子。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2025-01-29 21:05:14

Eslint-Plugin-Require-exteric-generics看起来像您想要的。

https://www.npmjs.coms.coms.coms.coms.coms.coms.com/package/package/eslint-lint-plugin-require - 解释生成

到您传递要执行通用类型的函数的名称的选项(例如usestatereact.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 or React.useState)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文