Not really a good idea unfortunately. Goldfish and tropical fish have pretty different needs that make them incompatible tank mates. The biggest issue is temperature - goldfish do best in cooler water (around 65-72°F) while tetras and guppies want it warmer (75-80°F). You'd be stuck in the middle trying to keep everyone happy, and nobody thrives that way. Plus goldfish are messy eaters and produce a ton of waste, which means your water quality swings wildly. Tropical fish are usually pickier about that stuff.
The predator thing is real too. Smaller fish like tetras could definitely get eaten, especially if your goldfish get hungry or startled. Even if they're not actively hunting, goldfish will mouth at anything that moves, and they've got that reputation for a reason. Your 40 gallons is actually decent sized, but it's not enough space to keep them far enough apart to prevent problems.
Best move is keeping them separate. Goldfish honestly need their own setup anyway - they get pretty big and live forever (seriously, a couple years is just the start), so a dedicated tank lets them do their thing without stress. Your tropical fish will be way healthier and less stressed without the temperature war and predation risk.