我尝试在旧的AngularJS项目中开始使用TypeScript 2.4.1。首先,我尝试将我的简单控制器重构为ts。在控制器上,我在编译过程中使用匿名函数get Error:(35, 11) TS2339:Property 'app' does not exist on type 'Window'.
(function (app) {
'use strict';
app.ReservationModule.controller('ItineraryController', ItineraryController);
ItineraryController.$inject = [
'SeatMapService',
'SeatMapSegments'
];
/**
* Controlling interaction between seatMap service and Itinerary view.
*/
function ItineraryController(SeatMapService:any, SeatMapSegments:any) {
const vm = this;
vm.deselectService = deselectService;
vm.show = show;
/**
* Deselect traveller seat on seatMap service by segment.
*/
function deselectService(traveller, segment) {
SeatMapService.deselectService(traveller, segment);
}
/**
* Returns true if segment has new seatMap service.
* @param segment
* @return {boolean}
*/
function show(segment) {
return SeatMapSegments.getSegment(segment).hasNewSeatsService();
}
}
})(window.app); // type script error reason is here
答案 0 :(得分:4)
让窗口动态化。
(<any>window).app
您还可以参考此问题: How do you explicitly set a new property on `window` in TypeScript?