3

我已经为 Eclipse Oxygen 安装了Angular2 Eclipse插件。我已经使用 angular CLI 创建了一个 angular2 项目,然后在 eclipse 中打开了该项目。

我试图将项目转换为 Angular 项目,但是当我右键单击项目并转到配置时,没有这样的选项。唯一的选项是“配置和检测嵌套项目..”,它会打开导入向导。

当我在 src/app/... 例如我的 databinding.component.html 中打开 html 模板文件时,HTML 编辑器显示丑陋的错误:

html编辑器中的错误

当我将鼠标悬停在错误上时,我看到所有错误都具有以下格式:

[ts] <error message>

一些例子:

[ts] Cannot find name 'aNumber'. Did you mean 'Number'?
[ts] Cannot find name 'innerText'.
[ts] Cannot find name 'h4'.

但是错误是不正确的。我可以毫无问题地使用 ng-serve 启动应用程序。

如何配置 eclipse 以使这些错误的错误消息消失?谢谢 :)

编辑#1

这是我的 Eclipse 打字稿配置,我看不出我可以在这里改变什么..

喜好

4

1 回答 1

9

正如@Angelo 提到的,这个错误是已知的,并且有一个临时的解决方法。

您需要转到此文件C:\Users\MyUser\eclipse-workspace\.metadata\.plugins\ts.repository\repositories\2.4.1\node_modules\typescript\lib\tsserver.js并更改这部分代码:

    Session.prototype.getDiagnosticsWorker = function (args, isSemantic, selector, includeLinePosition) {
        var _a = this.getFileAndProject(args), project = _a.project, file = _a.file;
        if (isSemantic && isDeclarationFileInJSOnlyNonConfiguredProject(project, file)) {
            return [];
        }
        var scriptInfo = project.getScriptInfoForNormalizedPath(file);
        var diagnostics = selector(project, file);
        return includeLinePosition
            ? this.convertToDiagnosticsWithLinePosition(diagnostics, scriptInfo)
            : diagnostics.map(function (d) { return formatDiag(file, project, d); });
    };

进入这个:

    Session.prototype.getDiagnosticsWorker = function (args, isSemantic, selector, includeLinePosition) {
        var _a = this.getFileAndProject(args), project = _a.project, file = _a.file;
        if (isSemantic && isDeclarationFileInJSOnlyNonConfiguredProject(project, file)) {
            return [];
        }
        if (ts.fileExtensionIs(file, ".html") &&
            project.getExternalFiles && project.getExternalFiles() && project.getExternalFiles().map &&
            !ts.contains(project.getExternalFiles(), file)) {
            return [];
        }
        var scriptInfo = project.getScriptInfoForNormalizedPath(file);
        var diagnostics = selector(project, file);
        return includeLinePosition
            ? this.convertToDiagnosticsWithLinePosition(diagnostics, scriptInfo)
            : diagnostics.map(function (d) { return formatDiag(file, project, d); });
    };
于 2018-06-04T14:12:05.380 回答