0

I've been unit-testing some code that depends on interfaces and classes I am unable to import, but can add to intellisense through d.ts files. Despite having the "include" property in my tsconfig mention those files, I get errors about how TypeScript couldn't compile because it couldn't find any of those interfaces I am using.

My tsconfig:

{
  "compilerOptions": {
    "target": "es6",
    "module": "CommonJS",
    "esModuleInterop": true,

    "sourceMap": false,
    "downlevelIteration": true,

  },
  "include": 
  [
    "_MainSource/**/*", 
    "Tests/**/*", 
    "@typeDefs/**/*"
  ],


}

The error I get:

error TS2503: Cannot find namespace 'RPG'.

My current test command:

mocha -r ts-node/register Tests/**/*.ts

I have tried adding a 'ts-node --files' to the test command, getting me what you see here:

mocha -r ts-node/register 'ts-node --files' Tests/**/*.ts

But then I get errors about how TS can't find ts-node (even though ts-node is installed, and the original command works fine on code that doesn't rely on the RPG namespace).

Tespy
  • 971
  • 2
  • 9
  • 18

1 Answers1

0

This is intentional, as those are only definition files, they are not meant to be compiled but to provide additional typing information for JavaScript files (which are in some cases already compiled). You can find more in this post.

Zer0
  • 1,580
  • 10
  • 28
  • I see... Though before I started using anything in the RPG namespace, TypeScript had no problem compiling other types in the d.ts files. Those types were in the global namespace, sure, but my setup didn't have access to the actual data types. Why did that work? – Tespy Aug 12 '20 at 00:18