Typescript 接口中firebase函数/storgae/数据库的写入类型

Typescript 接口中firebase函数/storgae/数据库的写入类型,typescript,Typescript,firebase函数/存储/管理的类型脚本类型是什么 所以我是typescript新手,正在将我的代码JS代码更新为typescript 在我的代码中,我正在创建上下文obj const context = { functions: functions, realtime: admin.database(), firestore: admin.firestore() admin: admin } 现在,我正在传递这个上下文,我想为它创建一个接口?有人能帮我弄清楚

firebase函数/存储/管理的类型脚本类型是什么

所以我是typescript新手,正在将我的代码JS代码更新为typescript

在我的代码中,我正在创建上下文obj

const context = {
    functions: functions,
    realtime: admin.database(),
    firestore: admin.firestore()
    admin: admin
}

现在,我正在传递这个上下文,我想为它创建一个接口?有人能帮我弄清楚上面的接口吗?一般来说,如何确定某事物的类型?

只需根据属性类型定义接口即可。
firestore
admin.firestore.firestore
界面,彼此相同

这是我的firebase admin示例(我不知道
函数是什么
):

我相信TS能够通过
typeof
关键字自动推断
context
对象的类型

// keep the code as-is:
const context = {
    functions: functions,
    realtime: admin.database(),
    firestore: admin.firestore()
    admin: admin
}

// then add:
type IContext = typeof context

您可以安全地传递此接口。无需手动声明它,除非您需要定制它以满足特定需求。

即使我没有为上下文声明接口,typescript也不会抱怨它。作为一名typescript开发人员,您会创建界面吗?@anny123目前有哪些问题需要解决?我不明白你的要求。我主要是要求上面的接口。我不太想知道,作为一个typescript开发人员,你什么时候为对象创建接口?@anny123大多数时候我只是让TS推断类型。在某些情况下,我将执行
const obj:SomePredefinedInterface={…}
,这通常意味着该接口比当前的
obj
实例更通用,并在其他地方多次使用。
// keep the code as-is:
const context = {
    functions: functions,
    realtime: admin.database(),
    firestore: admin.firestore()
    admin: admin
}

// then add:
type IContext = typeof context