Types TypeScript support
Closed this issue · 7 comments
Error using TypeScript.
TypeScript error in ./client/src/components/Clients/index.tsx(2,27):
Could not find a declaration file for module 'react-items-carousel'. ./client/node_modules/react-items-carousel/dist/react-items-carousel.js' implicitly has an 'any' type.
Try `npm install @types/react-items-carousel` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-items-carousel';` TS7016
1 | import React, { useState } from 'react'
> 2 | import ItemsCarousel from 'react-items-carousel';
| ^
3 | // import '@brainhubeu/react-carousel/lib/style.css'
4 | // import './Clietns.scss'
5 |
I recommend to you use dts gen created by Microsoft.
hi @wilo087 thanks for pointing that out, please create a PR, I'll be happy to review and merge
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@wilo087 were you able to find any solution ? to generate the typings or make it work for typescript ?
@kareemaly any idea how to use this in a typescript environment?
Really not, I just use another solution.
Hi @Oluwasetemi and other guys,
I just came across this issue and is still not fixed. It can be fixed by adding the react-items-carousel
module manually. Just do the following in your React application.
- Create a directory for your app
types
, named types, in the root directory of your application. - Create a sub-directory in the types directory, named react-items-carousel.
- Create a file
index.d.ts
in the sub-directory, i.e. react-items-carousel, and your directory structure will be like
project
|___node_modules
|___public
|___src
|
|___types
|
|___react-items-carousel
| index.d.ts
-
Declare the carousel module in the file
index.d.ts
, like the following.declare module "react-items-carousel";
-
Now add your
local types
directory to the TypeScript configuration filetsconfig.json
in thecompilerOptions
object. -
Exclude the root directory you just created for your local
types
, so that it will not be compiled. Yourtsconfig.json
file will look like the following after adding these two.
{
"compilerOptions": {
...
"typeRoots": [ "./types", "./node_modules/@types" ],
},
"exclude": [ "node_modules", "types" ],
...
}
And that's all, you are good to go to use the react-items-carousel
module with TypeScript
support.
@Jehangir-Wahid, thanks man, it works like a charm!
You just save-me some hours!!
how to show indicators in this library