I have a state that is expecting a string variable. It's a search term. I'm getting this from the search url. But even when I'm checking to see if it's a string I still get an error saying that a variable of type string cannot be string | null
let searched = useLocation().search;
const query = new URLSearchParams(searched);
const [searchedTerm, setSearchedTerm] = useState<string>(typeof query.get('term') === 'string' ? query.get('term') : '');
I specificaly check if it's a string and then add it. The error that I get is this:
Argument of type 'string | null' is not assignable to parameter of type 'string | (() => string)'.
Type 'null' is not assignable to type 'string | (() => string)'.