How can we create a string type with prefix/suffix word in typescript?

Viewed 822

I have a type like this:

type State = 'state1' | 'state2' | 'state3';

Now I want to define another type DefaultState like below code but don't want to write 'state[X]' manually. It should automatically map all possible state with string -default :-

type DefaultState = 'state1-default' | 'state2-default' | 'state3-default';
type AllState = State | DefaultState;

const s1: AllState = 'state1';
const s2: AllState = 'state2';
const s3: AllState = 'state1-default';

// All these values for s1, s2, s3 should be valid.

Do we have anything in typescript upto v4.0.0-beta or any version for this?

1 Answers
Related