RubenHerman
RubenHerman

Reputation: 1854

TypeScript: Unable to find reference when compiling

The Setup:
I created a TypeScript file (String.ts) to extend string:

interface StringConstructor {
    isNullOrEmpty(str: string): boolean;
    isNullOrWhiteSpace(str: string): boolean;
}

String.isNullOrEmpty = (str: string) => !str;
String.isNullOrWhiteSpace = (str: string) => { return (String.isNullOrEmpty(str)) ? false : str.replace(/\s/g, '').length < 1 };

The tsconfig.json files that I created contain:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "strict": true,
    "noEmitOnError": true,
    "module": "amd",
    "removeComments": true,
    "target": "es5",
    "declaration": true,
    "outFile": "./Common.js", --> Only this line changes in other tsconfig.json files (+ does not exist in highest located tsconfig.json file)
    "inlineSourceMap": true,
    "inlineSources": true,
    "lib": [
      "dom",
      "es5",
      "es2015.promise"
     ]
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

File Structure:

The problem(in the following order)
1) When I have one tsconfig.json (highest level), everything compiles ok
2) When I add a tsconfig.json in Common, everything compiles ok
3) When I add a tsconfig.json in Business, I get a compilation error that String.isNullOrWhiteSpace cannot be found.

Anyone knows what the problem could be and how to solve it?

(If more information is needed... let me know!)

Upvotes: 0

Views: 319

Answers (1)

Moinak Bhattacharyya
Moinak Bhattacharyya

Reputation: 111

String.ts is not included in compilation when you segregate the Business directory(ie it would need to be imported from elsewhere). You should have a separate common directory called for interfaces and common definitions.

Upvotes: 1

Related Questions