title: In TypeScript how can I handle for loops when using "import * as" syntax
body: <p>In TypeScript I'd like to import all modules from a file and iterate over them, but the compiler throws an error at build time. Would someone know what settings or syntax I should use to fix this?</p>
  <pre><code>import * as dependencies from './dependencies';
  
  for (const key in dependencies) {
    console.log(dependencies[key]());
  }
  </code></pre>
  <p>At build time the compiler throws the below error:</p>
  <pre><code>error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import(&quot;/src/dependencies/index&quot;)'.
    No index signature with a parameter of type 'string' was found on type 'typeof import(&quot;/src/dependencies/index&quot;)'.
  </code></pre>
  <p>tsconfig.json</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;allowJs&quot;: true,
      &quot;allowSyntheticDefaultImports&quot;: true,
      &quot;jsx&quot;: &quot;react&quot;,
      &quot;lib&quot;: [&quot;dom&quot;, &quot;es2018&quot;],
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;noUnusedLocals&quot;: true,
      &quot;noUnusedParameters&quot;: true,
      &quot;outDir&quot;: &quot;./dist&quot;,
      &quot;preserveConstEnums&quot;: true,
      &quot;removeComments&quot;: false,
      &quot;rootDir&quot;: &quot;./src&quot;,
      &quot;skipLibCheck&quot;: true,
      &quot;sourceMap&quot;: true,
      &quot;strict&quot;: true,
      &quot;target&quot;: &quot;es2018&quot;,
      &quot;forceConsistentCasingInFileNames&quot;: true,
      &quot;esModuleInterop&quot;: true,
      &quot;resolveJsonModule&quot;: true,
      &quot;isolatedModules&quot;: true
    },
    &quot;exclude&quot;: [&quot;node_modules&quot;],
    &quot;include&quot;: [&quot;**/*.ts&quot;]
  }
  </code></pre>
  <p><strong>EDIT:</strong></p>
  <p>As a workaround I'm doing something like this, but it seems redundant.</p>
  <pre><code>import * as dependencies from './dependencies';
  
  interface Collection {
    [key: string]: any;
  }
  
  const dependencyCollection: Collection = dependencies;
  
  for (const key in dependencyCollection) {
    console.log(dependencyCollection[key]());
  }
  </code></pre>