3

I am creating an app in react using the react template provided by visual studio 2017. I want to make use of react-cookie in my application. I have installed this lib using command

npm install react-cookie

But when i try to import it in my component it gives me the following error on compile time:

import { Cookies } from 'react-cookie';

(TS) Could not find a declaration file for module 'react-cookie'. 'D:/somepath/node_modules/react-cookie/lib/index.js' implicitly has an 'any' type. Try npm install @types/react-cookie if it exists or add a new declaration (d.ts) file containing declare module 'react-cookie'

I tried installing it using

npm install @types/react-cookie

But the console shows me a message that

@types/react-cookie is not in the npm registry. You should bug the author to publish it (or use the name yourself

I am very new to react so maybe i am making a silly mistake. Can somebody help me out as i need to use this library in my project.

Prasaad Patil
  • 357
  • 1
  • 5
  • 17
  • Check out the answer for this https://stackoverflow.com/questions/41462729/typescript-react-could-not-find-a-declaration-file-for-module-react-material/41631658 – illiteratewriter May 11 '18 at 12:47

1 Answers1

1

I found types definitions

{
  "dependencies": {
    "universal-cookie": "^2.1.2",
    "universal-cookie-express": "^2.1.2",
    "react-cookie": "^2.1.2"
  },
  "devDependencies": {
    "@types/universal-cookie": "git+ssh://git@github.com:S64/types-universal-cookie.git#v2.1.2-2",
    "@types/universal-cookie-express": "git+ssh://git@github.com:S64/types-universal-cookie-express.git#v2.1.2-2",
    "@types/react-cookie": "git+ssh://git@github.com:S64/types-react-cookie.git#v2.1.2-2"
  }
}

https://github.com/S64/types-react-cookie

open up git bash from start menu (WINDOWS)

ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
ssh-keygen -t rsa -C "user.email"

Add the id_rsa.pub key to SSH keys list on your GitHub profile.

if you are really interested look at this commit (passed tslint) https://github.com/ricardosaracino/heroes-react-ts/commit/19a9e0f55940c9ac7007e093d08eae9d17e7d7ba

Ricardo Saracino
  • 979
  • 2
  • 12
  • 28