为什么在尝试实现接口时flowtype会抱怨?

时间:2019-09-12 16:46:40

标签: javascript types flowtype

在定义libdef时,我有:

declare class Resource implements ResourceOptions {
        app ? : Express | Router;
        sequelize ? : Sequelize;
        model: any;
        endpoints ? : string[];
        actions ? : Array < "create" | "read" | "update" | "delete" | "list" > ;
        include ? : any[];
        pagination ? : boolean;
        updateMethod ? : "POST" | "PUT" | "PATCH";
        search ? : SearchOptions | SearchOptions[];
        sort ? : SortOptions;
        reloadInstances ? : boolean;
        associations ? : boolean;
        excludeAttributes ? : string[];
        readOnlyAttributes ? : string[];
        associationOptions: any;
        attributes: any;
        projects: any;
        controllers: any;
        create: Controllers$create;
        read: Controllers$read;
        update: Controllers$update;
        delete: Controllers$update;
        list: Controllers$list;
        all: Controllers$all;
        associationsInfo: any;
        use: any;
    }

和:

declare interface ResourceOptions {
        app ? : Express | Router;
        sequelize ? : Sequelize;
        model: any;
        endpoints ? : string[];
        actions ? : Array < "create" | "read" | "update" | "delete" | "list" > ;
        include ? : any[];
        pagination ? : boolean;
        updateMethod ? : "POST" | "PUT" | "PATCH";
        search ? : SearchOptions | SearchOptions[];
        sort ? : SortOptions;
        reloadInstances ? : boolean;
        associations ? : boolean;
        excludeAttributes ? : string[];
        readOnlyAttributes ? : string[];
    }

但是流量一直在抱怨,特别是关于endpoints ?: string[];

 • undefined [2] is incompatible with array type [3] in property endpoints.

我该怎么做才能使其正常工作?

1 个答案:

答案 0 :(得分:2)

我并不是真正的类和接口如何在流中交互的专家,但是基本上,该接口不允许该属性存在但未被定义的可能性。如果将void合并为属性类型,则错误将为go away

相关问题