Resolving paths in TypeScript outDir
<p>I'm writing a UI page object model testing project in TypeScript and I'm trying my best to avoid hideous nested imports. </p>

<p>I found the <code>paths</code> object for the <code>.tsconfig</code> file that fixes the issue in <code>.ts</code> files, but, because I compile into an <code>outDir</code>, my compiled <code>.js</code> files cannot resolve the module path. </p>

<p>I develop in a <code>model</code> directory and compile into a <code>src</code> directory.</p>

<p>I've set up my <code>.tsconfig</code> file as follows</p>

<pre><code>{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": false,
    "outDir": "src/",
    "baseUrl": "./model/",
    "paths": {
      "general.utils": [ "lib/general/general.utils" ],
      "pretest.setup": [ "lib/pretest.setup/pretest.setup" ],
      "tpapi": [ "lib/tpapi/tpapi" ],
      "*": [ "*" ]
    }
  },
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false
}
</code></pre>

<p>That <code>paths</code> allows me to </p>

<p><code>import { chooseRandomValueFrom } from 'general.utils';</code></p>

<p>from a <code>.ts</code> file that is in <code>model</code>, but won't resolve in a <code>.js</code> file in <code>src</code>.</p>

<p>This is an <code>npm</code> type project that is run with <code>npm test</code>. That command executes a script that compiles, runs tests from, and deletes the <code>src</code> directory.</p>

<pre><code>#!/bin/bash

npm run compile:ts
node_modules/webdriverio/bin/wdio
npm run clean:ts
</code></pre>