reactjs - 为子文件夹声明模块

标签 reactjs typescript

我正在尝试为模块“react-facebook-login/dist/facebook-login-render-props”创建类型,这是 https://github.com/keppelen/react-facebook-login 的一部分.请注意,它位于一个子文件夹中。

我创建了一个包含以下模块声明的 d.ts 文件:

declare module "react-facebook-login/dist/facebook-login-render-props" {

    interface RenderProps {
        onClick: Function;
        isDisabled: boolean;
        isProcessing: boolean;
        isSdkLoaded: boolean;
    }

    interface ReactFacebookLoginProps {
        appId: string;
        callback(userInfo: ReactFacebookLoginInfo): void;
        onFailure?(response: ReactFacebookFailureResponse): void;

        autoLoad?: boolean;
        buttonStyle?: React.CSSProperties;
        containerStyle?: React.CSSProperties;
        cookie?: boolean;
        cssClass?: string;
        disableMobileRedirect?: boolean;
        fields?: string;
        icon?: string | React.ReactNode;
        isDisabled?: boolean;
        language?: string;
        onClick?(event: React.MouseEvent<HTMLDivElement>): void;
        reAuthenticate?: boolean;
        redirectUri?: string;
        scope?: string;
        size?: "small" | "medium" | "metro";
        textButton?: string;
        typeButton?: string;
        version?: string;
        xfbml?: boolean;
        isMobile?: boolean;
        tag?: Node | React.Component<any>;
        render?(props: RenderProps): void;
    }

    interface ReactFacebookFailureResponse {
        status?: string;
    }

    interface ReactFacebookLoginInfo {
        id: string;
        accessToken: string;
        name?: string;
        email?: string;
    }

    interface ReactFacebookLoginState {
        isSdkLoaded?: boolean;
        isProcessing?: boolean;
    }

    class ReactFacebookLogin extends React.Component<
        ReactFacebookLoginProps,
        ReactFacebookLoginState
        > {}
}

但它似乎没有被拾取,因为我收到一个错误:

error TS7016: Could not find a declaration file for module 'react-facebook-login'. '.....\node_modules\react-facebook-login\dist\facebook-login-with-button.js' implicitly has an 'any' type.

我该怎么做才能键入位于包子文件夹中的这个文件?

最佳答案

原来问题不是文件在子文件夹中。

对于寻找解决方案的 Google 员工,这就是我最终得到的:

declare module "react-facebook-login/dist/facebook-login-render-props" {

    export interface RenderProps {
        onClick: Function;
        isDisabled: boolean;
        isProcessing: boolean;
        isSdkLoaded: boolean;
    }

    interface ReactFacebookLoginProps {
        appId: string;
        callback(userInfo: ReactFacebookLoginInfo): void;
        onFailure?(response: ReactFacebookFailureResponse): void;

        autoLoad?: boolean;
        buttonStyle?: React.CSSProperties;
        containerStyle?: React.CSSProperties;
        cookie?: boolean;
        cssClass?: string;
        disableMobileRedirect?: boolean;
        fields?: string;
        icon?: string | React.ReactNode;
        isDisabled?: boolean;
        language?: string;
        onClick?(event: React.MouseEvent<HTMLDivElement>): void;
        reAuthenticate?: boolean;
        redirectUri?: string;
        scope?: string;
        size?: "small" | "medium" | "metro";
        textButton?: string;
        typeButton?: string;
        version?: string;
        xfbml?: boolean;
        isMobile?: boolean;
        tag?: Node | React.Component<any>;
        render(props: RenderProps): void;
    }

    interface ReactFacebookFailureResponse {
        status?: string;
    }

    interface ReactFacebookLoginInfo {
        id: string;
        accessToken: string;
        name?: string;
        email?: string;
    }

    interface ReactFacebookLoginState {
        isSdkLoaded?: boolean;
        isProcessing?: boolean;
    }

    export default class ReactFacebookLogin extends React.Component<
        ReactFacebookLoginProps,
        ReactFacebookLoginState
        > {}
}

关于reactjs - 为子文件夹声明模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50999424/

相关文章:

typescript - 使用 passport-jwt 在 nestJs 框架中进行角色验证

reactjs - 当我们 `import { foo }` 时,为什么我们不能 `export foo` 而必须 `export { foo }` ?

javascript - 当用户单击作为父 div 的子级的按钮时,如何隐藏父 div 并将其替换为另一个 div?

javascript - ReactJS 错误的组件被从 DOM 中删除

reactjs - react onClick 事件

javascript - 如何在 typescript 中使用表单元素

javascript - Grunt-Browserify 忽略选项

typescript - 有没有一种方法可以放弃我所做的类型定义的副本,使它们在全局范围内可用?

Angular FormControl 对象能够接受任何类型的输入值,还是仅限于 typescript 原始类型?

typescript - VS Code 资源管理器 : Hide the generated . 仅 d.ts 文件