使用angular-cli创建TypeScript定义文件

时间:2017-01-11 07:40:30

标签: typescript angular-cli

我想用angular-cli创建TypeScript定义文件。在angular-cli.json中指定了tsconfig文件,但是当我在"declaration"中将true修改为tsconfig.json时,它无效。

我的tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

angular-cli.json

{
  "project": {
    "version": "1.0.0-beta.24",
    "name": "app-name"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
      "styles": [
        "styles.scss",
        "../node_modules/font-awesome/css/font-awesome.min.css",
        "assets/fix/ubuntu.css"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "addons": [
    "../node_modules/font-awesome/fonts/*.+(otf|eot|svg|ttf|woff|woff2)",
    "../node_modules/ubuntu-fontface/fonts/*.+(otf|eot|svg|ttf|woff|woff2)"
  ],
  "packages": [],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "sass",
    "prefixInterfaces": false,
    "inline": {
      "style": false,
      "template": false
    },
    "spec": {
      "class": false,
      "component": true,
      "directive": true,
      "module": false,
      "pipe": true,
      "service": true
    }
  }
}

我也没有out-tsc目录。运行ntsc -p我得到了定义文件,但我想用angular-cli创建。

1 个答案:

答案 0 :(得分:0)

tsconfig的一个问题是您无法在定位时将es6设置为模块 es5

检查compiler options here

根据您的项目,在模块中尝试CommonJSes2015作为目标。