I have a function that validates input
export const isValidString = (value: string | null | undefined): boolean => {
return value != null && value.length > 0 && value.trim() != "";
};
const func = (input: string) =>{
// some code
}
const someFunction = (input : string | null | undefined) => {
if(isValidString(input)){
func(input); //This is the line that is complaining
}
};
the call to the func is throwing an error which I'm not sure why as the isValidString is making sure the input is not undefined. Any reason why ?
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2345)
However, if I just do
if(input != null) func(input);
Everything works
