All lithium ion batteries (whether in cell phones, tablets, laptops, or electric vehicles) have the most longevity when kept at a state of charge between about 20% and 80% and never getting too warm.
For example, my Prius Plug In battery is software limited (by Toyota) to never charge above 85% and never below 23%. This is also why Tesla recommends only charging to 100% only right before very long trips where you really need the extra range. Cell phone batteries are extremely similar to EV batteries, but it's not as practical to never charge to 100% in cell phones (but it also doesn't cost thousands of dollars if you need it replaced).
With the very generous size of the battery of the Pixel 2 XL I wish there was a way to only have it charge to 80% or 90% if we wanted (thinking for overnight where you can't watch the state of charge).