在React Native

时间:2018-07-15 10:50:02

标签: reactjs react-native npm npm-install

我最近安装了一个新程序包以在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".

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

1 个答案:

答案 0 :(得分:1)

在src中添加了文件夹类型。然后将任何文件.d.ts

/src/types/anything.d.ts

// anything.d.ts

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

这似乎可行,欢迎提供带有解释的更好答案。