引用角度 1.5 时指令语法错误无效'reference'



我昨天已经升级到Typescript 2.0.3,并将引用路径更新为

/// <reference types="angular" />

在安装了Angular 1.5x的类型之后,使用以下命令

npm install -s @types/angular

我在构建项目时得到错误,并且错误不会消失。

无效的"引用"指令语法

如何解决这个问题?

/// <reference types="angular" />
/// <reference types="d3" />
(function () {
    'use strict';
    var app = angular.module('charts', []);
    app.controller('mainCtrl', function mainCtrl($scope, appService) {
        var vm = this;
        vm.data1 = [1, 2, 3, 4];
        vm.data2 = [4, 5, 7, 11];
        vm.update = function (d, i) {
            vm.data1 = appService.GetRandomData();
            console.log('new data1', vm.data1);
        };
        vm.update2 = function (d, i) {
            vm.data2 = appService.GetRandomData();
            console.log('new data2', vm.data2);
        };
    });
    app.directive('barChart', function ($timeout) {
        var chart = d3.custom.barChart();
        return {
            restrict: 'E',
            replace: true,
            scope: true,
            bindToController: {
                data: '=',
            },
            controller: 'mainCtrl',
            controllerAs: 'ctrl',
            link: function (scope, element, attrs, ctrl) {
                var chartEl = d3.select(element[0]);
                chartEl.datum(ctrl.data).call(chart)
            }
        }
    });
    app.directive('chartForm', function () {
        return {
            restrict: 'E',
            replace: true,
            controller: 'mainCtrl',
            templateUrl: 'chartform.html'
        }
    });
    app.service('appService', function () {
        this.GetRandomData = function () {
            var rdata;
            rdata = d3.range(~~(Math.random() * 50) + 1).map(function (d, i) {
                return ~~(Math.random() * 100);
            });
            return rdata;
        }
    });
} ());

我在构建服务器VSTS中得到这个错误。

升级类型脚本版本解决了我的问题。

在package中,json: from

"typescript": "2.8.3"

 "typescript": "3.5.1"

我已经更新了工作空间设置文件.vscode/settings.json中的typescript路径,以指向最新的typescript版本。这将使VS Code使用最新版本的typescript。

{
    "typescript.tsdk": "C:\Users\UserName\AppData\Roaming\npm\node_modules\typescript\lib"
}

我不认为这是问题,因为当我在集成终端运行tsc -v时,我得到2.0.3

现在我开始修复编译器错误。

有用的链接:

  • 我可以使用相对路径来配置typescript sdk吗?
  • "无效的'reference'指令语法" Typescript2 @types references

对于mac用户来说,如果你全局安装TypeScript,你的路径是这样的:

  "typescript.tsdk": "/Users/me_me_me/.nvm/versions/node/VERSIION/bin/tsc"

最新更新