gpt4 book ai didi

angular - 我收到错误 "Spread types may only be created from object types.ts(2698)"

转载 作者:行者123 更新时间:2023-12-03 15:07:32 28 4
gpt4 key购买 nike

import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { map } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class FirestoreDbService {

constructor(private db: AngularFirestore) { }

getBuildList() {
// return this.db.collection('Builds').valueChanges();
return this.db.collection('Builds').snapshotChanges().pipe(
map(docArray => {
return docArray.map(doc => {
console.log('==', doc.payload.doc.id);
console.log('$==$', doc.payload.doc.data());
return{
id: doc.payload.doc.id,
... doc.payload.doc.data()
}
})
})
)
}
}

在最后一行,我得到了错误。我认为这与 typescript 有关。任何帮助表示赞赏

最佳答案

使用as关键字:

... doc.payload.doc.data() as {} 

这将告诉编译器将 doc.payload.doc.data()视为对象。

关于angular - 我收到错误 "Spread types may only be created from object types.ts(2698)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60421089/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com