亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我嘗試實現接口時,為什么 flowtype 會抱怨?

當我嘗試實現接口時,為什么 flowtype 會抱怨?

慕絲7291255 2021-10-14 15:51:25
在定義 a 時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.我該怎么做才能讓它發揮作用?
查看完整描述

1 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

我并不是真正了解類和接口如何在流中交互的專家,但基本上接口不允許屬性存在但未定義的可能性。如果你聯合void到屬性類型,錯誤就會消失。


查看完整回答
反對 回復 2021-10-14
  • 1 回答
  • 0 關注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號