【问题标题】:Webstorm - Typescript, AngularJS and generator-ng-poly Getter/SetterWebstorm - Typescript、AngularJS 和 generator-ng-poly Getter/Setter
【发布时间】:2015-10-28 11:52:39
【问题描述】:

我有一个名为 lobby-constants.ts 的文件:

module lobby.constants {
  export class Constants {

    static get Default() : any {
      return {
        baseUrl: 'http://localhost:2999'
      };
    }
  }
}

我将通过以下方式加载它:

.constant('appConstant', lobby.constants.Constants.Default);

不幸的是,我在 Webstorm 中收到以下错误消息,这很合理,因为 gulp 将 ECMAScript 版本 3 作为默认输出。

app\lobby\constants\lobby-constants.ts(8,16): 1056 访问器仅 面向 ECMAScript 5 及更高版本时可用。

有没有办法改变 gulpfile 中的这个特定设置?

generator-ng-poly:https://github.com/dustinspecker/generator-ng-poly

【问题讨论】:

  • generator-ng-poly 文档似乎暗示它使用 Babel 来支持 ES6,所以......也许他们忘记将 ES5 目标传递给 tsc编辑 似乎有一个关于支持 ES6/ES2015 的未解决问题 ~ github.com/dustinspecker/generator-ng-poly/issues/170
  • 当时我使用的是“typescript”选项。有没有办法将 ECMA 5 隐式声明为输出?

标签: javascript angularjs typescript gulp webstorm


【解决方案1】:

在生成的gulpfile.js文件中,修改

config.tsProject = $.typescript.createProject({
  declarationFiles: true,
  noExternalResolve: false
});

out 选项像这样传递

config.tsProject = $.typescript.createProject({
  declarationFiles: true,
  noExternalResolve: false,
  out: 'es5'
});

这适用于较旧的生成项目。较新的项目是使用 gulpfile.js 中的 config.tsSourceProject 和 config.tsTestProject 生成的,这两个项目都需要使用 out 选项进行修改。

【讨论】:

  • 我已经进行了您描述的更改,但我仍然收到相同的错误消息。我可能需要更改其他设置吗?
猜你喜欢
  • 2015-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多