I have upgraded to Typescript 2.0.3 yesterday and updated the reference path to
/// <reference types="angular" />
after installing the typings for Angular 1.5x using the following command
npm install -s @types/angular
I get the error when I build the project and the error doesn't go away.
Invalid 'reference' directive syntax
How does one fix this?
/// <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;
}
});
} ());
I was getting this error in the build server, VSTS.
Upgrading the type script version resolved my issue.
In package,json: changed from
"typescript": "2.8.3"
to
"typescript": "3.5.1"
I have updated the typescript path in workspace settings file .vscode/settings.json
to point to the latest typescript version. This will make VS Code to use the latest version typescript.
{
"typescript.tsdk": "C:\\Users\\UserName\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"
}
I didn't assume this to be the problem because when I run tsc -v
in the integrated terminal, I got 2.0.3
.
Now I am onto fixing the compiler errors.
Helpful links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With