title: Defining Typescript types for my own code in a different folder
body: <p>I'm creating a library where I want to autogenerate Typescript types for the user's code. For that I would love to put the type definitions in a different folder, so that they are out of sight, but the IDE can still pick them up.</p>
  <p>This is possible with Typescript modules, but I couldn't find a way to define types for an &quot;ambient&quot; module. A simplified code example for how I would like the file structure to be:</p>
  <pre class="lang-js prettyprint-override"><code>    // src/pages/WelcomePage.ts
      export const message = 'hi'
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>    // src/index.ts
      import { message } from './pages/WelcomePage'
      console.log(message) // message should be of type &quot;Message&quot;, not of type &quot;string&quot;.
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>    // types/pages/WelcomePage.d.ts
      // This doesn't work.
      // Can we make it work somehow?
      declare module &quot;pages/WelcomePage&quot; {
          type Message = string
          export const message: Message
      }
  </code></pre>
  <p>tldr: I would like all my generated types to be in <code>types/...</code> and they should define types for <code>src/...</code>.</p>