Preserve the input element type in unique (#23208)
Previously the element type of the output was the smallest type that
would fit the union of the input's individual element types. Now the
output has an identical element type to the input. Fixes #22696.