0

Not quite familiar with custom modules. No idea how to resolve this issue. I am trying to migrate a code and I am stuck at this.

Module file in root of the folder - settings.d.ts

type Settings = {
  group: {
    field1: string;
    field2: string;
    ...
  };
};

declare module 'settings' {
  const s: Settings;
  export = s;
}

In tsconfig.json (same location as the settings.d.ts)

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "types": ["@emotion/react"],
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
  },
  "include": [
    "src",
    "settings.d.ts",
  ],
  "exclude": [
    "node_modules",
    "build"
  ]
}

Imported in my-code.ts. Tried the following imports with no typescript errors. I can also "go to file" to the actual settings.d.ts in vscode

import * as settings from 'settings';

import settings from 'settings';

import { field } from 'settings';

But the compilation fails with error

./src/.../folder/my-code.ts Module not found: Can't resolve 'settings' in '/Users/.../folder'

UPDATE A missing package in node_modules that my settings.d.ts is trying to augment with declarations. Far more complicated to add that package -- the way it was added in the legacy codebase. Wanna puke. Anyways, there's nothing wrong with the snippets above.

duduwe
  • 888
  • 7
  • 16
  • Does this answer your question? [Import class in definition file (\*d.ts)](https://stackoverflow.com/questions/39040108/import-class-in-definition-file-d-ts) – Andy Ray Jan 16 '23 at 18:30
  • Thanks @AndyRay. Went tracing the original codebase. Like I mentioned, I am migrating codes, but not all. A package is missing in the node_modules that settings.d.ts is trying to augment with declarations. It'll be a complicated thing to do, since I will only be migrating a portion. Anyways, there's nothing wrong with the snippets above. Thanks for the help. – duduwe Jan 16 '23 at 19:50

0 Answers0