请问,我该如何修复此代码?
Observable.fromEvent(this.getNativeElement(this.term), 'keyup')
.debounceTime(500)
.map(ev => ev.key)
.scan((acc, one) => acc + one)
.subscribe(term => console.log(term));
我收到错误Property' key'类型' {}'上不存在
更新
在@ jb-nizet的评论中(thx这么多:)) 我用
解决了这个问题Observable.fromEvent<KeyboardEvent>(this.getNativeElement(this.term), 'keyup')
答案 0 :(得分:1)
使用
map(ev => ev['key'])
或告诉TypeScript您的初始Observable是Observable<KeyboardEvent>
const obs: Observable<KeyboardEvent> = Observable.fromEvent(this.getNativeElement(this.term), 'keyup');
obs.debounceTime()...