参数 'changes' 隐含地有一个 'any' type.ts(7006)
Parameter 'changes' implicitly has an 'any' type.ts(7006)
收到这个错误,请告诉我如何解决这个问题,谢谢。
getClients(): Observable<Client[]> {
// get clients with id
this.clients = this.clientsCollection.snapshotChanges().map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
尝试将代码更改为:
snapshotChanges().map((changes:any) => {...})
和
returns changes.map((action: any) ...
看来你 运行 你的 angular 严格项目你有几个选择。
更好的做法是使用严格模式,它可以让你在以后的道路上省去很多麻烦,虽然有时它会自己引起头痛,但相信我,从长远来看,这是值得的 运行 .
- 在你的例子之前添加
:any
:
getClients(): Observable<Client[]> {
// get clients with id
this.clients = this.clientsCollection.snapshotChanges().map(changes:any => {
return changes.map(action:any => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
在您的 tsconfig.json
中将此 "noImplicitAny": false
添加到 "compilerOptions":{}
这将取消来自编译器的警报。
创建正确类型的界面并使用它。
这样编译器可以在需要时纠正你并防止你犯错误或试图访问空引用。
最佳实践是选项 3,但它并不总是正确的或值得构建界面,只需考虑它即可。尽可能避免 :any
。
收到这个错误,请告诉我如何解决这个问题,谢谢。
getClients(): Observable<Client[]> {
// get clients with id
this.clients = this.clientsCollection.snapshotChanges().map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
尝试将代码更改为:
snapshotChanges().map((changes:any) => {...})
和
returns changes.map((action: any) ...
看来你 运行 你的 angular 严格项目你有几个选择。
更好的做法是使用严格模式,它可以让你在以后的道路上省去很多麻烦,虽然有时它会自己引起头痛,但相信我,从长远来看,这是值得的 运行 .
- 在你的例子之前添加
:any
:
getClients(): Observable<Client[]> {
// get clients with id
this.clients = this.clientsCollection.snapshotChanges().map(changes:any => {
return changes.map(action:any => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
在您的
tsconfig.json
中将此"noImplicitAny": false
添加到"compilerOptions":{}
这将取消来自编译器的警报。创建正确类型的界面并使用它。 这样编译器可以在需要时纠正你并防止你犯错误或试图访问空引用。
最佳实践是选项 3,但它并不总是正确的或值得构建界面,只需考虑它即可。尽可能避免 :any
。