In the rules for bonus actions it states:
You choose when to take a bonus action during your turn, unless the bonus action's timing is specified ...
I have seen this quote used to justify some gratuitous rulings that I am extremely unsure about. I think there is an assumption that you can't take bonus actions during the resolution of mechanics, but I have seen that many people do not share this opinion.
Take the example of Misty Step. Misty Step is a bonus action spell that lets you teleport 30ft. Can you use Misty Step in the following situations (all examples take place on the player's turn);
- When you are the target of an opportunity attack to avoid the attack?
- Once an opportunity attack has hit you but damage has not been dealt to avoid damage?
- When pushed off a cliff to avoid falling to the bottom?
- When using a Necklace of Fireball on your own position, but teleporting away before the damage is dealt?
- When stepping on to a pressure plate trap but before the trap activates?
- Some other examples you can think of to illustrate the RAW limits to bonus actions