Angular: 属性 未找到点击但处于正常订阅中

Angular: Property not found tap but is in normal subscription

我正在尝试使用去抖动时间,但出现了一个奇怪的打字稿错误。我可以在普通订阅中使用 value.searchSting,但是通过管道描述我使用了 tap,但我收到一条错误消息 Property 'searchString' does not exist on type 'unknown'

我做错了什么。我确定点击应该没问题。

this.myForm.valueChanges.subscribe( value => console.log(value.searchString)); // No errors

这很好用,value.searchString

下没有红色下划线
this.myForm.valueChanges.pipe(
  debounceTime(400),
  distinctUntilChanged(),
  tap(value => {

     
    console.log(value.searchString); // Underlined Typescript error
    
      let searchTerm = value.searchString; // Underlined Typescript error

      this.filteredUserNames = this.users.filter((userName) =>
        userName.searchTerms
          .toLowerCase()
          .indexOf(searchTerm.toLowerCase()) !== -1)
  })
).subscribe();

Typescript 不满意并在此处加下划线 value.searchString 并给出上述错误。很奇怪。我做错了什么,有没有解决方法。

因为你没有提到value对象的类型。只需将其作为 any 对象提及即可。像这样

tap((value:any) => {

 
console.log(value.searchString); // Underlined Typescript error

  let searchTerm = value.searchString; // Underlined Typescript error

  this.filteredUserNames = this.users.filter((userName) =>
    userName.searchTerms
      .toLowerCase()
      .indexOf(searchTerm.toLowerCase()) !== -1)
  })