How to include custom types/namespaces in typescript compilation build

Viewed 142

I am building a typescript library to be used by other projects.

I have some modules in it which reference types and interfaces from several namespaces under the main library namespace. They are declared in d.ts files in a root @types folder included in the typeRoots of tsconfig.json.

Everything works fine in the IDE during development, tests and at compile time, no errors.

The problem is once compiled in dist folder, while my namespaces are still referenced in generated modules d.ts files, the actual d.ts files referencing them are nowhere to be found, making the resultant compiled library unusable (raising a "TS2503: error Cannot find namespace" if I try to use it elsewhere).

How would one is supposed to make its custom namespaces included by typescript compilation in the resulting build ?

Folder structure :

├── _@types
│   ├── main_namespace
│   │   ├── sub_namespace
|   |   |   └── index.d.ts
│   │   └── index.d.ts
│   └── index.d.ts
├── src
│   ├── module1
│   │   └── index.ts
│   ├── module2
│   │   └── index.ts
│   └── module3
│       ├── index.ts
│       ├── submodule1.ts
│       └── submodule2.ts
├── test

tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "lib": [
      "esnext"
    ],
    "target": "esnext",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "pretty": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "forceConsistentCasingInFileNames": true,
    "preserveConstEnums": true,
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "declarationDir": "dist/@types",
    "baseUrl": ".",
    "outDir": "dist",
    "typeRoots": [
      "@types",
      "node_modules/@types"
    ]
  },
  "include": [
    "@types",
    "src"
  ]
}

0 Answers
Related