0
votes

I want to use the toggle-switch-react-native component in my Typescript app. I tried installing it like this:

yarn add toggle-switch-react-native --save
@types/toggle-switch-react-native

However, I still get an error that:

Could not find a declaration file for module 'toggle-switch-react-native'. '/Users/grannyandsmith/insta/app/node_modules/toggle-switch-react-native/ToggleSwitch.js' implicitly has an 'any' type.
  Try `npm install @types/toggle-switch-react-native` if it exists or add a new declaration (.d.ts) file containing `declare module 'toggle-switch-react-native';`

How can I define its types? Is there an alternate? Am I installing it correctly?

2

2 Answers

2
votes

This library does not have types, so you need to create a "custom type":

Create a folder called types/@custom_types.

Inside that folder, create a file called declarations.d.ts.
On the first line of that file, add

declare module "toggle-switch-react-native" 
0
votes

In npm you should use npm i toggle-switch-react-native --save or npm i toggle-switch-react-native --save-dev. These have been replaced by yarn add and yarn add --dev in yarn. Try this way, might work