【问题标题】:Where do you add .d.ts files in React Native在 React Native 中在哪里添加 .d.ts 文件
【发布时间】:2018-12-23 03:57:28
【问题描述】:

我最近安装了一个用于 React Native 的新包。与其他包一样,我在 Visual Studio Code 中被提示:

[ts]
Could not find a declaration file for module 'react-native-material- 
dropdown'. '/home/stumfi-mobile/123-app/node_modules/react-native- 
material-dropdown/index.js' implicitly has an 'any' type. Try `npm 
install @types/react-native-material-dropdown` if it exists or add a new 
declaration (.d.ts) file containing `declare module 'react-native- 
material-dropdown';`

通常这是一个微不足道的修复,因为我只需键入:

npm install @types/react-native-material-dropdown

但是今天失败了。我了解到 npm 最近遇到了一些令牌被泄露的问题:

npm WARN notice Due to a recent security incident, all user tokenshave 
been invalidated. Please see 
https://status.npmjs.org/incidents/dn7c1fgrr7ng for more details. To 
generate a new token, visit https://www.npmjs.com/settings/~/tokens or 
run "npm login".

在调查了他们的链接后,我决定我需要手动进行此操作(并希望能学到一些东西)。我在哪里创建包含 `declare module 'react-native-material-dropdown' 的文件 (.d.ts) 文件

【问题讨论】:

    标签: reactjs react-native npm npm-install


    【解决方案1】:

    在 src 中添加了文件夹类型。然后是anything.d.ts文件

    /src/types/anything.d.ts

    //anything.d.ts

    声明模块“react-native-material-dropdown”;

    这似乎有效,欢迎提供更好的解释。

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多