So say you have some pokemon but none of them are the right types for the next gym. Your first instinct might be to buy or catch some new ones but I have a better solution that should cost less and take probably a bit more time but possibly less time.
What you should do is sort out which of your highest level pokemon don't have a disadvantage against the type that the gym is due to their own types, after you've done that you go to their stat pages and see if you can change their movesets to be more effective against the type that the gym uses. If you can't find anything or don't know what types work against that gym and which types don't, I'd recommend going to the pokemon database website, it's usually the third or fourth result when you look up a pokemon type or just a pokemon. It'll tell you what's super effective and what isn't against the type/pokemon you've searched, and if you look up a pokemon it will show you what moves it can learn. And then you can get your pokemon those skills with the buy skills button. You might be surprised with what moves can go on what pokemon. For example, say you need to beat the grass gym and have a Furret. Furret can learn flamethrower. Then you get those skills and put them on your pokemon, and be sure to press Save Attack Order when you're done. Then if you need to level up the pokemon still, you can go refight what gyms you've already beaten or go to Newpine or the Eastbourne shore or the grass in the Dorocoast docks area and grind for wingulls and diner coupons. Once you are satisfied with the amount of coupons you have you can go to a diner of your choice and train the pokemon against the npcs there. You might not need to level them higher than what you think the gym will use, but it's good to try just in case. As long as your pokemon aren't one-shotted and can land hits on the gym leaders pokemon, you are golden. You can also get type-enhancement items from the npcs that stand next to the main counter in pokemarts.