不要在Typescript IntelliSense中包含测试定义文件并输出

时间:2017-02-14 09:33:15

标签: angularjs typescript

我正在开发Angular.js中的应用。我遇到了@types/angular-mocks定义适用于src/**下所有文件的问题。我希望angular-mocks的定义文件仅适用于与src/**/*.spec.ts匹配的文件。

  • 防止模拟方法在真实控制器中显示
  • 防止在d.ts输出文件
  • 中引用模拟库

以下代码显示了我的典型控制器和d.ts输出问题:

我-controller.ts

import * as ng from 'angular';

export class MyController {
  constructor(public $timeout: ng.ITimeoutService) {}

  method() {
    // I don't want this method to be shown
    this.$timeout.flush();
  }
}

我-controller.d.ts

/// <reference types="angular" />
/// <reference types="angular-mocks" />
// I want to prevent the above reference from being added
import * as ng from 'angular';
export declare class MyController {
    $timeout: ng.ITimeoutService;
    constructor($timeout: ng.ITimeoutService);
    method(): void;
}

如果相关,则为tsconfig.json设置:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es6",
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "dist",
    "newLine": "LF",
    "sourceMap": true,
    "skipLibCheck": true,
    "removeComments": false,
    "importHelpers": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "experimentalDecorators": true
  },
  "include": [
    "src/**/*"
  ]
}

我还没有找到一个很好的方法来实现这一目标。任何帮助将不胜感激。

0 个答案:

没有答案