Reputation: 276
I would like to know if there is a way to concatenate two typescript types as one example :
type Size = 'xl' | 'xxl' ...;
let textSize: 'text-' & Size;
// So my type is something like : 'text-xl' | 'text-xxl'
Upvotes: 2
Views: 556
Reputation: 168843
By using a template literal type.
type Size = 'xl' | 'xxl';
type TextSizeType = `text-${Size}`;
TS resolves TextSizeType
to
type TextSizeType = "text-xl" | "text-xxl"
which sounds like what you want.
Upvotes: 5