I am using a library called "react-images" which doesn't have up-to-date type definitions. As a result, I need to open up the namespace and create them. The problem is, the library has both default and named exports and I'm having trouble getting typescript to handle both kinds of exports correctly.
Named imports work out of the box, all you need to do is declare the classes. If you want a default export though, you need to use the export syntax discussed here. Unfortunately, when I added the line export = Carousel, the named imports broke.
I need to be able to do this:
// project.tsx
import Carousel, { Modal, ModalGateway } from "react-images";
Here's what I've got so far:
// reactImages.d.ts
import React from "react";
declare module "react-images" {
interface ModalProps {
onClose: () => void;
}
declare class Modal extends React.Component<ModalProps> {
public constructor(props: ModalProps);
}
declare class ModalGateway extends React.Component<> {
public constructor(props: ModalGatewayProps);
}
interface CarouselProps {
currentIndex: number;
views: { source: string }[];
}
declare class Carousel extends React.Component<CarouselProps> {
public constructor(props: CarouselProps);
}
export = Carousel
}