2

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'

1 Answer 1

5

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.