title: TypeScript assertion on every item of array
body: <p><a href="https://stackoverflow.com/q/57812051/1183252">I defined an array of an <code>interface</code></a></p>
  
  <pre><code>interface Converter&lt;T = Buffer&gt; {
    name: string;
    uuid: CUUID;
    decode: (value: Buffer) =&gt; T;
  }
  
  type Converters = ReadonlyArray&lt;Converter&lt;any&gt;&gt;;
  </code></pre>
  
  <p>but for my usecase I need to cast every item in that array using a <code>const</code> assertion:</p>
  
  <pre><code>const infoConverter = {
    name: "info",
    uuid: "180a",
    decode: (v: Buffer) =&gt; v.toString()
  } as const;
  
  const pressureConverter = {
    name: "pressure",
    uuid: "1810",
    decode: (v: Buffer) =&gt; v.readInt32BE(0)
  } as const;
  
  const converters = [infoConverter, pressureConverter];
  </code></pre>
  
  <p>I would not mind doing that, but I am writing a library and users of that library are providing that array. So in order for the library to work properly I will have to ask the users to use a <code>const</code> assertion whenever they work with it, which is not quite optimal. </p>
  
  <p>For me, it would be great if the could just provide the library with their data and I could automatically do a <code>const</code> assertion.</p>
  
  <p>So  I have this class</p>
  
  <pre><code>class Service&lt;C extends Converters&gt; {
    private converters?: Converters;
  
    constructor(converters?: C) {
      this.converters = converters;
    }
  }
  </code></pre>
  
  <p>and I wonder if there is a way I could do something like this:</p>
  
  <pre><code>class Service&lt;C extends Converters&gt; {
    private converters?: EveryItemIsAConst&lt;Converters&gt;;
  
    constructor(converters?: C) {
      this.converters = converters as EveryItemIsAConst&lt;C&gt;;
    }
  }
  </code></pre>
  
  <p>and the users could just do</p>
  
  <pre><code>const infoConverter = {
    name: "info",
    uuid: "180a",
    decode: (v: Buffer) =&gt; v.toString()
  };
  
  const pressureConverter = {
    name: "pressure",
    uuid: "1810",
    decode: (v: Buffer) =&gt; v.readInt32BE(0)
  };
  
  const converters = [infoConverter, pressureConverter];
  
  const service = new Service(converters)
  </code></pre>
  
  <p>and the <code>EveryItemIsAConst</code> would make sure <code>as const</code> is applied to every item in the <code>converters</code> array.</p>