【发布时间】:2018-09-08 16:31:31
【问题描述】:
我有一个使用 preact-cli 和 preact-cli-typescript-plugin 设置的项目。一切都可以编译、运行和工作,但我不知道如何为 Firebase 功能导入 typescript 声明。这是问题的一个示例。
import { CollectionReference, DocumentSnapshot, Firestore } from 'firebase/firestore';
import { Observable } from 'rxjs';
export default class FirestoreDatabase {
private readonly itemCollection: CollectionReference;
constructor(firestore: Firestore) {
this.itemCollection = firestore.collection('items');
}
items(): Observable<DocumentSnapshot> {
return Observable.create(observer =>
this.itemCollection.onSnapshot(observer)
);
}
}
该类工作得很好,并且符合预期,但我收到警告:
[ts] Could not find declaration file for module 'firebase/firestore'. '[project root]/node_modules/firebase/firestore/dist/index.cjs.js' implicitly has type of any.
在第一行代码上执行了四次。 Firebase 的所有类型及其功能模块都在 node_modules/firebase/index.d.ts 中,但我不确定如何让编译器看到。
【问题讨论】:
标签: typescript firebase preact