My build is in my signature and I'm expecting 6-8 years.
Two big questions:
Will the hardware fail? Impossible to know. SSDs are less likely to have issues, and if you leave the machine on all the time it's more prone to failure.
Will Apple move away from Intel with their own chips and then stop supporting Intel in a future version of macOS? Impossible to know for sure but we can look at the rumors and the history.
Rumors point to yes, sometime in the 2020-2021 timeframe. Rumors say it will start on the lower end MacBooks and things like that before moving up to the Pro machines. This especially makes sense if the Mac Pro is coming out this year and there are no rumors about it using Apple CPUs. The other reason it makes sense to start on the lower end is because it gives professional app developers time to adjust for the new architecture.
Historically, Apple supported PowerPC for only about four years of new OS X updates after transitioning to Intel (I think it was only two versions though, because back then Apple updated less frequently). But Apple also has a lot more Macs on the market today, more resources at their disposal, and a higher expectation for longevity. So given those things I figure if they move to Apple CPUs next year at the earliest, that's one year, then four years for macOS updates, and then one year until macOS gets updated again and the machine is officially out of date. But even in this case you can still expect security updates for a while, so the machine just won't stop working unless something hardware related fails—you just won't get the new features. So for me I figure 6-8 years seems reasonable and given the work I do will be adequate. I might do 6 years if it's starting to feel slow because, say, I got a crazy new camera setup that shoots 8K60 12bit or something nuts with 120MP stills. And 8 years would be if it still seems like it's running fine for my workload, which I doubt will actually be that crazy by then, but I will be doing more video production work later this year on the iMac Pro my new boss just ordered me, so who knows where that will take me. I also might get the itch to get that 31.6" 6K display after it comes to the iMac Pro and upgrade on the lower end of my time frame.
Now this is all speculation on my part, but I'm deeply analytical and this is exactly what my thinking process was before I decided to pull the trigger. Just make sure you don't sink yourself. Only buy enough Mac that you could replace it if something goes wrong after a year. There's also AppleCare, but that only goes for three years and personally I wouldn't buy it on a desktop. I've owned a lot of Apple hardware and in my experience if something doesn't go wrong in the first year then it's probably good to last you until it's no longer relevant and becomes slow and needs an upgrade anyway. For desktops this is even more true because they just stay on your desk and don't go with you so they're less likely to break than a mobile device or laptop. Anyway, hope this helps, but don't take it as an absolute.