title: Where should I put the index.d.ts file?
body: <p>I am writing a nodeJS service that uses a bunch of npm modules without @types.</p>
  
  <p>The tsc error message tells me that I need to add index.d.ts file, but it doesn't tell me where to put it. My helper.spec.ts file which also imports the same modules also cannot detect index.d.ts when run with jest</p>
  
  <p>I put the file in my root along with tsconfig.json, but it doesn't detect it. My files and structure look like this:</p>
  
  <p>Folder structure</p>
  
  <pre><code>node_modules
  build
      app.js
      helper.js
      another.js
  spec
      - helper.spec.ts
      - another.spec.ts
  src
      - app.ts
      - helper.ts
      - another.ts
  tsconfig.json
  index.d.ts
  jest.config.json
  package.json
  package-lock.json
  </code></pre>
  
  <p>tsconfig.json</p>
  
  <pre><code>{
    "compilerOptions": {
      "target": "es6",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
      "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
      "allowJs": true,                       /* Allow javascript files to be compiled. */
      "outDir": "build",                        /* Redirect output structure to the directory. */
      "strict": true,                           /* Enable all strict type-checking options. */
    },
    "include": [
      "src/**/*.ts",
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
  }
  </code></pre>
  
  <p>index.d.ts</p>
  
  <pre><code>declare module "module-one";
  declare module "module-two";
  declare module "module-three";
  </code></pre>
  
  <p>package.json</p>
  
  <pre><code>{
    "dependencies": {
      "module-one": "^2.0.4",
      "module-two": "^1.3.3",
      "module-three": "0.0.3",
      "@types/lodash": "^4.14.129",
    },
    "devDependencies": {
      "@types/jest": "^24.0.13",
      "@types/node": "^9.6.0",
      "cpx": "^1.5.0",
      "jest": "^24.8.0",
      "ts-jest": "^24.0.2",
      "typescript": "^3.4.5"
    },
    "scripts": {
      "start": "cd build &amp;&amp; node app.js",
      "test": "jest",
      "build": "tsc",
      "postinstall": "npm run-script build"
    },
  }
  </code></pre>
  
  <p><strong>Where does tsc and jest expect the index.d.ts?</strong></p>
  
  <p>Some articles that suggested to create one index.d.ts for each module e.g. <code>./types/module-one/index.d.ts</code>, <code>./types/module-two/index.d.ts</code>, <code>./types/module-three/index.d.ts</code> and then edit tsconfig.json <code>compilerOptions.typeRoots</code> to include <code>./types</code> folder.</p>
  
  <p>But I want to just have 1 index.d.ts with all the declarations.</p>
  
  <p>When I edit tsconfig.json <code>include</code> to include <code>index.d.ts</code> file, I find that tsc can compile the files in my src folder. However when I run jest, it is still complaining that my module index.d.ts is missing.</p>
  
  <p><strong>EDIT:</strong>
  If I remove my tsconfig.json, then jest will run correctly without complaining about missing module, but then I cannot tsc build my src files.</p>
  
  <p>If I keep the tsconfig.json, then tsc will build my src files, but jest will complain that module-one is undefined.</p>
  
  <p><strong>EDIT 2:</strong>
  I found that if I set <code>[jest.config.ts].globals.ts-jest.diagnostics = false</code>, then the error goes away and all my test pass! But I don't think that is the correct fix?</p>