2

I do have 2 main folders in my project:

  • src/*.ts
  • test/*.test.ts

In the src folder there is a interface named IImportRow.ts

interface IImportRow {
    transactionId?: string;
    transactionApiId?: string;
    ...
}

this interface can be found for every other ts file in the src folder.

However in the test folder the TS cannot find the interface

var row: IImportRow = {
    transactionId: '10',
    ...
};

[ts] Cannot find name 'IImportRow'.

Is this an expected behaviour? What should I do in order to fix it?

here are my tsconfig.json configuration

"compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "dist",
    "strict": false,
    "noImplicitAny": false,
    "strictPropertyInitialization": false,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
},

1 Answer 1

2

There's an additional portion of the TsConfig file which lets you specifies which directories should be included/excluded for inspection by the TS compiler. You just need to add your tests folder to the include array. Here's an example from one of my projects that you can tweak as needed.

{
    "compilerOptions": {
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false,
        "allowSyntheticDefaultImports": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es6",
        "sourceMap": true,
        "allowJs": true,
        "outDir": "./build",
        "baseUrl": "./src",
        "skipLibCheck": true
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules", "build", "**/*.spec.ts"]
}
Sign up to request clarification or add additional context in comments.

2 Comments

you men to add the "src" folder instead of "test" right?
I believe you would need to add both in your situation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.