I have a conditional type that uses a generic type T
to determine an Array<T>
type. As a contrived example:
type X<T> = T extends string ? Array<T> : never;
The issue I am having is when I provide a union type, it is being distributed as a union of 2 array types instead of an array of my union type.
// compiler complains because it expects Array<'one'> | Array<'two'>
const y: X<'one' | 'two'> = ['one', 'two'];
Is there a way to type this such that my conditional type produces an Array<'one' | 'two'> if the condition is met?