Natively, I don't believe that's possible.
I have been scouting for every existing setting in my phones for more than a decade now, and I do not remember having ever seen it as an option.
I have no idea if it's possible to do that with an app, but if I had to guess I would say it's not?
Personally what I ended up doing was to create a naming convention, and add every number I want to block as a contact under that name convention.
In most messaging apps, you can block existing contacts, that way in apps like Telegram, WhatsApp, these "blocked" contacts won't be able to see your profile.
What I do is that I add each number to a new contact, that way you can backup these undesirable numbers with all the rest of your contacts.
Every now and then, I go to my messaging apps, and block the new undesirable contacts I have added.
I am totally aware that it is unpractical, it's a lot of labor, and it's probably not worth it, but I've been doing that for years, because I would regularly switch between iOS and Android, and it was the only reasonable way to keep that list of both contacts and blocked numbers between these two platforms.
In practice, contacts are trusted phone numbers in a sense, so I'm not sure what the security implications of behaving that way are, but I've been getting 1-3 undesired phone calls per week, and at some point I just figured that I would go a little less insane if I could not lose that list of numbers when switching platforms.