Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do you add .d.ts files in React Native

I've recently installed a new package to use in React Native. As with other packages I was prompted in Visual Studio Code to:

[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';`

Usually this is a trivial fix, as I just type:

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

However today this failed. And I learned that npm has had some issues with tokens being compromised recently:

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".

After investigating their links, I've decided I need to to this manually (and hopefully get to learn something). Where do I create this file (.d.ts) file containing `declare module 'react-native-material-dropdown'

like image 980
middleonly Avatar asked Jan 02 '23 03:01

middleonly


1 Answers

Added folder types in src. And then the file anything.d.ts

/src/types/anything.d.ts

//anything.d.ts

declare module "react-native-material-dropdown";

This seems to work, a better answer with explanation is welcome.

like image 155
middleonly Avatar answered Jan 05 '23 17:01

middleonly