我正在尝试为firebase-functions模块创建基本的flow-typed定义。
此模块的用例示例如下:
// @flow
import * as functions from 'firebase-functions'
import create from './tasks/create'
const { firestore } = functions
exports.createCharacter = firestore
.document('characters/{characterID}')
.onCreate((snapshot, context) => create(snapshot, context))到目前为止,我已经在flow-typed/firebase-functions.js中创建了这个
// @flow
declare module 'firebase-functions' {
declare class firestore {
static document(path: string): void;
}
}我现在被困在从文档链接的.onCreate(部件上,流不允许我扩展document而static document.opnCreate是有效的。
发布于 2018-07-23 00:04:05
在流类型的库代码中,您告诉Flow document函数返回空。
然后,您的应用程序代码将使用该函数的结果,该函数之前声明为void。我怀疑这就是编译器抱怨的原因:在空对象上调用onCreate不起作用(或者至少是类型系统的因素)。
如果这样做会发生什么:static document(path: string): firestore。因为这就是(大概:我不知道Firebase)这里正在发生的事情。
当然,现在需要声明function onCreate。
同样值得注意的是,对于像firebase这样的Javascript模块,您不需要自己编写流类型声明(除非您想/需要这样做)。flow-typed install firebase@5.x.x应该为您安装一个社区创建(或生成)的流类型文件
https://stackoverflow.com/questions/51456434
复制相似问题