javascript - 当我尝试实现接口(interface)时,为什么 flowtype 会提示?

标签 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[];
    }

但是 Flow 一直在提示,特别是关于 endpoints ?: string[]; :

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

我该怎么做才能让它发挥作用?

最佳答案

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

关于javascript - 当我尝试实现接口(interface)时,为什么 flowtype 会提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57911258/

相关文章:

javascript - 不正确的 Angular ,错误的边计算

haskell - RankNTypes 和教堂数字

docker - 错误 : unsatisfiable constraints: flow (missing) in Alpine Linux

javascript - 我们可以在任何地方使用 `const` 而不是 `let` 吗?

javascript - 使用javascript修改复选框

javascript - 在两个整页上打印两个图像

javascript - 将 url 中的 json 数据存储到 cordova 的数据库中

sql - SQL Server 中的 SYSNAME 数据类型是什么?

c++ - 初始化nullptr_t时,0与其他整数如何区分?

flowtype - 忽略 node_modules 但不是 flowtype 中的一些