【问题标题】:React Typescript: @types/react-router-dom vs react-router-domReact Typescript:@types/react-router-dom 与 react-router-dom
【发布时间】:2021-05-24 15:20:04
【问题描述】:

我是 Typescript 的新手,第一次在 React 项目中使用它。我真的对@types npm 包感到困惑。请告诉我@types/react-router-domreact-router-dom 之间的区别以及应该使用哪个包?

谢谢!

【问题讨论】:

  • @types/whatever 是一个包,可为您提供任何包的类型。 react-router-dom 是实际库,另一个给出 TS 的类型

标签: reactjs typescript


【解决方案1】:

react-router-dom - 必需 - 实际包
@types/react-router-dom - 可选 - 为 typescript 项目添加类型

正如 Li357 所说:@types/whatever 是一个包,可为您提供 typescript 项目的任何包的类型

【讨论】:

    【解决方案2】:

    install @types/react-router-dom- 这个包有内置的类型声明。您可以在代码中使用这些类型定义。

    【讨论】:

    • 看起来更像是评论而不是答案。
    • 好,你给个答案,我向你学习。
    • 我的意思是,我认为你的帖子没有回答这个问题。比如看Medet Tleukabiluly的回答。
    • 当然,我需要学习,如何给出答案
    • 没什么可得罪的,先生,我是来学习的。
    猜你喜欢
    • 2021-10-30
    • 1970-01-01
    • 2021-05-10
    • 2017-12-05
    • 2017-10-22
    • 2019-05-30
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    相关资源
    最近更新 更多