【问题标题】:typescript angular2.d.ts error "Expecting new line or semicolon"typescript angular2.d.ts 错误“期待新行或分号”
【发布时间】:2015-07-13 22:59:28
【问题描述】:

我最新的WebStorm10.0.2 引发关于"angular2.d.ts" 的错误,即“期待新行或分号”。在第 15-19 行和第 32-37 行。

Angular2 团队在 5 分钟开始示例中犯了错误?我不敢相信,这一定是我的错。

所以:

我按照“angular2的5分钟快速入门”(https://angular.io/)一步步克隆。

我已经将 'index.html' 和 'app.ts' 从 'complete' 移动到 Base-Path。

我还将我的 WebStorm10.0.2 编译器版本更改为包含 typescriptService.js 的自定义目录。

还是不行……

我的 typescript 版本是 1.5Beta。

interface List<T> extends Array<T> {
}
interface Type {}

declare module "angular2/angular2" {
  function bootstrap(appComponentType: any): void;
  function Component({
    selector,
    properties,
    hostListeners,
    injectables,
    lifecycle,
    changeDetection
    }:{
      selector:string,
      properties?:Object,
      hostListeners?:Object,
      injectables?:List<any>,
      lifecycle?:List<any>,
      changeDetection?:string
    });

  function View({
      templateUrl,
      template,
      directives,
      formatters,
      source,
      locale,
      device
    }: {
      templateUrl?: string,
      template?: string,
      directives?: List<Type>,
      formatters?: List<Type>,
      source?: List<any>,
      locale?: string,
      device?: string
    });
  function For();
  function If();
}

【问题讨论】:

  • 这里似乎编译得很好。您确定错误在此文件中吗?它是否有正确的行尾(例如 Unix 或 Windows)?
  • Typescript 2.1.4 和最新的 Webstorm 刚开始出现这个问题。我认为一切仍然运行良好,但我得到所有关于波浪状红线的强迫症......

标签: angular typescript typescript1.5


【解决方案1】:

在命令行通过tsc -v检查你的tsc版本,看看结果是不是1.5.0-beta。您可能使用的是较早版本,因为您的系统中安装了多个版本(一个通过 npm,其他可能在您安装 Visual Studio 版本时)。

要检查tsc 的已安装版本(如果您在Windows 环境中),请使用命令行并键入where tsc,如果您的目录比npm 多,结果将是一个目录列表。到您的 Path 系统变量并删除它们。

一定要打开一个新的命令行以便再次测试tsc,因为旧的路径变量不会刷新已经打开的命令行。

【讨论】:

  • 这是非常有趣的帮助。但是,我不确定它是否能解决问题。这不应该是评论吗?
  • 好吧,我刚刚尝试将其更改为评论部分,但似乎我需要 50 声望才能做到这一点。
【解决方案2】:

我使用的是 WebStorm 10.0.4,默认配置为 TypeScript 1.4。在我重新配置 WebStorm 以使用 TypeScript 1.5 beta 之前,它给了我“缺少分号”的类型错误。它位于首选项 -> 语言和框架 -> TypeScript -> 编译器版本中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 2023-03-03
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    相关资源
    最近更新 更多