gpt4 book ai didi

reactjs - 使用默认导出和命名导出在 typescript 中声明模块

转载 作者:行者123 更新时间:2023-12-04 11:45:38 29 4
gpt4 key购买 nike

我正在使用一个名为“react-images”的库,它没有最新的类型定义。因此,我需要打开命名空间并创建它们。问题是,该库同时具有默认导出和命名导出,我无法让 typescript 正确处理这两种导出。

命名导入开箱即用,您需要做的就是声明类。如果你想要一个默认的导出,你需要使用 the export syntax discussed here .不幸的是,当我添加行 export = Carousel 时,命名的导入坏了。

我需要能够做到这一点:

// project.tsx

import Carousel, { Modal, ModalGateway } from "react-images";

这是我到目前为止所得到的:

// 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
}

最佳答案

尝试这个:

export { Modal, ModalGateway };
export default Carousel;

关于reactjs - 使用默认导出和命名导出在 typescript 中声明模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59060762/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com