const [user, setUser] = useState(null);
Since you havn’t given this a type, typescript has to try to infer it. It sees you passed in a null, so it assumes this state is (and always will be) null. Instead, you need to specify the type, as in:
interface UserData {
username: string;
password: string;
prevState: null
}
//...
const [user, setUser] = useState<UserData | null>(null);