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

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'

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.

Related

React-aws-s3 installed but error 'Could not find a declaration file for module 'react-aws-s3''

I have ran yarn add react-aws-s3 several times and it is in my package.json file: "react-aws-s3": "^1.5.0",but for some reason I am still getting an error on this line: import S3 from 'react-aws-s3'; that reads:
Could not find a declaration file for module 'react-aws-s3'. 'c:/Users/e096752/Documents/Cole's Git Repos/CyberpunkAPI/frontend/node_modules/react-aws-s3/dist/react-aws-s3.js' implicitly has an 'any' type.
Try `npm i --save-dev #types/react-aws-s3` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-aws-s3';`ts(7016)
So then I tried running yarn add #types/react-aws-s3 but got this error:
error An unexpected error occurred: "https://registry.yarnpkg.com/#types%2freact-aws-s3: Not found".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\e096752\\Documents\\Cole's Git Repos\\CyberpunkAPI\\frontend\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
It is also interesting to me that every time I have run either the install command or the add types command it has made me choose a version of react-router-dom which doesn't make much sense to me.
What is happening and what can I do to fix this probelm?
There are no typings for the react-aws-s3 in the DefinitelyTyped repo, so you cannot use the suggested command, but you can try the second suggestion: add a new declaration (.d.ts) file containing "declare module 'react-aws-s3';"
or you can try disable noImplicitAny and/or strict options in your tsconfig.json, so compiler will not complain about it.

Could not find a declaration file for module 'hclust'

I npm installed this module and it is showing in the dependencies of my package.json. When I import { clusterData } from 'hclust', VS code tells me Could not find a declaration file for module 'hclust'. '/Users/danielsteman/Desktop/dev/spotify_cluster_analysis/webapp/reactTensor/node_modules/hclust/index.js' implicitly has an 'any' type. Try npm i --save-dev #types/hclust if it exists or add a new declaration (.d.ts) file containing declare module 'hclust';ts(7016). I also tried to run npm i --save-dev #types/hclust but I'm getting a 404 not found error. I'm not sure how to solve this issue.
As #types/hclust doesn't exist, you'll need to create your own .d.ts declaration file for the hclust module.
When you do so, you may also choose to submit it to DefinitelyTyped so that others may benefit from it.

Not Found #types/react-bootstrap-table2-editor

I am using react-bootstrap-table2, but i can't install for react-bootstrap-table2-editor typescript
Could not find a declaration file for module 'react-bootstrap-table2-editor'. 'node_modules/react-bootstrap-table2-editor/lib/index.js' implicitly has an 'any' type.
Try `npm install #types/react-bootstrap-table2-editor` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-bootstrap-table2-editor';`ts(7016)
Can you give me some advice?
Run npm install #types/react-bootstrap-table-next
These aren't official types so they might not work that well.
Another option is to add // #ts-ignore above your import. This will mean no typescript support for that package but no error either

Unable to resolve published NPM module in project

I recently published a simple React module that I wrote in TypeScript. I tested my module by importing the local package into a project, and it worked flawlessly. However, now that I've published the module, whenever I try to import it into a project, I get the following error:
Failed to compile.
./src/...
Module not found: Can't resolve '<module>' in '.../src/...'
Package is listed in both package.json and package-lock.json, and the module shows up in node_modules. Additionally, VS Code doesn't throw any fits, so I'm not quite sure what could be the issue.
NPM, being the "Node Package Manager" interprets packages as node modules. in the documentation, it says it will try to load a folder by looking for a package.json file, and resolving the path in main relative to the folder it found.
So when publishing a package with a build step, always make sure to build it before its published (there is a prepublish hook for this, in the scripts object in package.json).
The other thing is to make sure that the package being published refers to the correct main, bin (if applicable), and module (if applicable) paths in the package.json file. if the source file is src/mylib.coffee and the built file is dist/mylib.js, the package.json must contain { "main": "dist/mylib.js" } in order that someone installing this module as a dependency into their node_modules folder would require the correct file.
in short make sure "main" in package.json points to the right file!

Cannot use recordRTC in react project

I cannot import RecordRTC from 'recordrtc'
I have installed the node module, but when I try to import it, i receive the following error:
Could not find a declaration file for module 'recordrtc'. '/Users/jnelson/Documents/GitHub/VidApp/node_modules/recordrtc/RecordRTC.js' implicitly has an 'any' type.
Try `npm install #types/recordrtc` if it exists or add a new declaration (.d.ts) file containing `declare module 'recordrtc';` TS7016
I've tried simply declaring record rtc as an any type in a .d.ts file but that did not seem to help. I feel like this should be a common issue and either a simple solution or someone has made a .d.ts file for this?
I created the app with react-ionic. The error message above is from a local web browser from my desktop
Try npm install #types/recordrtc --save
The above error occurred because you are using TypeScript with your React application.

Resources