1

I try start use TypeScript 2.4.1 on my old AngularJS project. Firstly I try to refactor my simple controller to ts. On controller, I use anonymous function in compile process 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
Edgaras Karka
  • 7,400
  • 15
  • 61
  • 115

1 Answers1

6

Make window dynamic.

(<any>window).app

You can also reference this question: How do you explicitly set a new property on `window` in TypeScript?

Chris Sharp
  • 2,005
  • 1
  • 18
  • 32
  • Seems like you just copied someone else's answer. If you think the two questions are the same, then vote to close as a duplicate. – Tom Fenech Oct 13 '17 at 10:47
  • 1
    Seems like I answered the question and referenced another question. Calling me down won't help this guy. My answer will. – Chris Sharp Oct 13 '17 at 10:52
  • 1
    And your whole thing of copying an answer is ridiculous. I already knew the answer and found the post that I learned it from (and that I had already upvoted) and linked it. EVERY answer is copied from somewhere, even if it's the doc, and I don't see people getting downvoted for those. – Chris Sharp Oct 13 '17 at 11:59