This is intended as a very general question on spell targeting but let's focus on a very specific example.
The fire bolt cantrip description states:
You hurl a mote of fire at a creature or object within range (120ft). Make a ranged spell attack against the target. On a hit, the target takes 1d10 fire damage. A flammable object hit by this spell ignites if it isn’t being worn or carried.
The formulation seems very weirdly specific to me. While I am allowed to shoot my fire bolt at any specific target within 120ft, I am apparently not allowed to shoot it in a random direction if there is no target within 120ft in that direction. The requirement of having a target is an explicit part of the spell description. The literal interpretation of this description would imply that I cannot just shoot my fire bolt in a horizontal upwards direction (in order to give a signal, like a flare gun) if there is nothing above me. However, if I spot a bird or an insect flying directly above my head at an altitude of 120ft, then I would be allowed to use my fire bolt as a flare gun by just target that poor being.
This got me thinking: What would happen if the bird that I target is not a real bird but an illusion created by a hostile mage, unbeknownst to me? (e.g. let's say that that mage used the Minor Illusion cantrip.) Would I still be able to shoot the fire bolt at that "bird"? Let's take a look at Xanathars Guide To Everything, p.85-86:
INVALID SPELL TARGETS
A spell specifies what a caster can target with it: any type of creature, a creature of a certain type (humanoid or beast, for instance), an object, an area, the caster, or something else. But what happens if a spell targets something that isn't a valid target? For example, someone might cast charm person on a creature believed to be a humanoid, not knowing that the target is in fact a vampire. If this issue comes up, handle it using the following rule.
If you cast a spell on someone or something that can't be affected by the spell, nothing happens to that target, but if you used a spell slot to cast the spell, the slot is still expended. If the spell normally has no effect on a target that succeeds on a saving throw, the invalid target appears to have succeeded on its saving throw, even though it didn't attempt one (giving no hint that the creature is in fact an invalid target). Otherwise, you perceive that the spell did nothing to the target.
Thus, according to this rule by WoTC themselves, the act of succeeding to cast the spell itself should betray no information about whether my target was valid or not. That means that I am allowed to cast fire bolt at any object or any perceived object within my range. In particular, it seems that I would be able to cast my fire bolt at that illusory bird.
Taking that logic a step further, what would happen if were the one to have created the illusory bird above my head? It would be absurd if was allowed to target an illusion created by another spellcaster with fire bolt, but I was forbidden from targeting my own illusion with fire bolt. To sum up, according to the most sensible interpretation of the official rules, I can use fire bolt as a flare gun, if I first create an illusory object above my head with Minor Illusion.
However, this seems very unintuitive to me. I am a spellcaster, so why I can't I just shoot a fire bolt in any direction I desire? Why do I need to jump through hoops to create an illusion that I can then target? Why does the act of the fire bolt being created and shot away from my location depend on the existence of another object far away from me? (In a physics formulation: there seems to be a nonlocal coupling between the point where the spell is created and its target.) Should maybe any air molecule or any point in space (assuming I am in a vacuum) count as a valid "object / target" for me to direct my fire bolt at? What is an "object"?
Note that this question can easily be asked for any other spell that mentions a targeting requirement in its description. I am asking from the perspective as a DM because I am trying to implement a logically consistent framework for magic. My intuition would be to just drop the targeting requirement from the spell description altogether.