title: Paramterized classes in Typescript?
body: <p>I'm trying to reduce some boilerplate in a Typescript project using DDD.
  My goal is to have a quick way to make a strongly typed Value Object where the only value is a string with a bounded length.</p>
  <p>My first attempt was this:</p>
  <pre class="lang-js prettyprint-override"><code>
  type BoundedStringProps = {
    value: string;
  };
  
  export function makeBoundedString(minLength: number, maxLength: number) {
    return class BoundedString extends ValueObject&lt;BoundedStringProps&gt; {
      private constructor(props: BoundedStringProps) {
        super(props);
      }
  
      get value() {
        return this.props.value;
      }
  
      public static create(props: BoundedStringProps): Result&lt;BoundedString&gt; {
        const guardRes = Guard.combine([
          Guard.againstNullOrUndefined(props.value, &quot;value&quot;),
          Guard.inRange(props.value?.length ?? 0, minLength, maxLength, &quot;value&quot;),
        ]);
  
        if (!guardRes.succeeded) {
          return Result.fail(guardRes.message);
        }
  
        return Result.ok(new BoundedString(props));
      }
    };
  }
  
  </code></pre>
  <p>And then it would be used like:</p>
  <pre class="lang-js prettyprint-override"><code>const MyValueObjectName = makeBoundedString(1, 100);
  </code></pre>
  <p>This works in the sense that MyValueObjectName is now a class with a bounded length but it's not recognised by typescript as a type and so assigning it to an interface without &quot;typeof&quot; doesn't work.</p>
  <pre class="lang-js prettyprint-override"><code>
  const SomeEntityName = makeBoundedString(1, 100);
  
  interface SomeEntityProps = {
   name: SomeEntityName; // Value not a type
  }
  </code></pre>
  <p>Is there anyway I can achieve what I want with as little code as possible (ideally a one-liner)?</p>