Reputation: 1023
I am trying to use debounce time and I am getting a strange typescript error. I can use value.searchSting in the normal subscription, but with the piped description I use tap and I get an error saying Property 'searchString' does not exist on type 'unknown'
What am I doing wrong. I'm sure tap should be fine with this.
this.myForm.valueChanges.subscribe( value => console.log(value.searchString)); // No errors
This works fine, no red underline under 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 is not happy and underlines value.searchString here and gives the above error. Very strange. What am I doing wrong and is there a workaround.
Upvotes: 0
Views: 160
Reputation: 2663
Because you have not mentioned the type of value object. Just mention it as an any object. Something like this
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)
})
Upvotes: 1