I have an issue where type (text: string) => void
is not assignable to type intersection ((text: string) => void) & (() => any) & ...
My code looks as follows:
import React, { Component } from 'react';import { SearchBar } from 'react-native-elements';export default class SearchBarComponent extends Component { state = { search: '', } updateSearch = (search: string) => { this.state = { search }; }; render(){ return(<div><SearchBar platform="default" round onChangeText={(text) => (this.updateSearch(text))} placeholder="Search..." value={this.state.search} /></div> ) }}
And my error message states:
Type error: Type '(text: string) => void' is not assignable to type '((text: string) => void) & ((text: string) => void) & (() => any) & (() => any) & (() => any) & ((text: string) => void) & (() => any) & (() => any) & (() => any)'. Type '(text: string) => void' is not assignable to type '() => any'. 18 | platform="default" 19 | round> 20 | onChangeText={(text) => (this.updateSearch(text))} | ^ 21 | placeholder="Search..." 22 | value={this.state.search} 23 | />
I suspect that I need to do type assertion as in https://www.tutorialsteacher.com/typescript/type-assertion, but I cannot quite figure it out. How do I do type assertion on anonymous functions?