How can I include custom declaration files in typescript?

Viewed 404

I'm having a lot of trouble including custom types in my code and I'm not sure what I'm doing wrong.

My file structure is:

project/
├── utils
|   ├── file.ts
|   ├── file.d.ts

file.d.ts includes:

declare module 'name' {
    export interface nameagain { ... }
}

In file.ts I include it using:

import type { nameagain } from 'name'

Instead of this working I get the error: "Cannot find module 'name' or its corresponding type declarations. Does anyone have advice on how to do this correctly?

Edit 1: My tsconfig:

{
"compilerOptions": {

  /* Basic Options */
  "target": "es2017",     
  "module": "commonjs", 
  "lib": ["es2020", "DOM"],
  "sourceMap": true,

  /* Strict Type-Checking Options */
  "strict": true,

  /* Module Resolution Options */
  "moduleResolution": "node",
  "esModuleInterop": true,       /

  /* Experimental Options */
  "experimentalDecorators": true, 
  "emitDecoratorMetadata": true,        

  /* Advanced Options */
  "resolveJsonModule": true,
  "forceConsistentCasingInFileNames": true,

  "typeRoots": [
    "./node_modules/@types",
    "./utils"
  ],
  "paths": {
    "*": ["./utils/*"]
  }
}

}

0 Answers
Related