0

I'm trying to use the module react-image-gallery. However there are no types found for this package using npm.

npm install @types/react-image-gallery returs 404.

Following this answer I tried to declare ImageGallery like this: const ImageGallery = require('react-image-gallery');

This gives no compiler warning but the application fails at runtime.

I can make everything work by setting "noImplicitAny": false in tsconfig.json but I do not wan't to disable this globally.

How can I mark my import as any?

I have tried the following but it does not work:

import ImageGallery: any from 'react-image-gallery';
import (ImageGallery as any) from 'react-image-gallery';
import { ImageGallery as any } from 'react-image-gallery';
Community
  • 1
  • 1
Ogglas
  • 62,132
  • 37
  • 328
  • 418

1 Answers1

2

Followed this guide here first: https://stackoverflow.com/a/44046969/3850405

Added a new folder called react-image-gallery with a index.d.ts file. Content:

import * as React from "react";

export class ImageGallery extends React.Component<any, any> {

}

export default ImageGallery;

After this everything worked and the component could be imported normally with import ImageGallery from 'react-image-gallery';

Community
  • 1
  • 1
Ogglas
  • 62,132
  • 37
  • 328
  • 418