【问题标题】:TypeScript error TS2339: Property 'app' does not exist on type 'Window' [duplicate]TypeScript 错误 TS2339:“Window”类型上不存在属性“app”[重复]
【发布时间】:2018-03-25 10:38:00
【问题描述】:

我尝试在我的旧 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

【问题讨论】:

    标签: angularjs typescript


    【解决方案1】:

    使窗口动态化。

    (<any>window).app

    你也可以参考这个问题: How do you explicitly set a new property on `window` in TypeScript?

    【讨论】:

    • 好像你只是抄袭了别人的答案。如果您认为这两个问题相同,请投票以重复结束。
    • 好像我回答了这个问题并引用了另一个问题。叫我下来对这家伙没有帮助。我的答案会。
    • 而你复制答案的整个过程都是荒谬的。我已经知道答案并找到了我从中学到的帖子(并且我已经投票了)并将其链接起来。每个答案都是从某个地方复制的,即使是文档,我不认为人们会因为这些而被否决。
    猜你喜欢
    • 1970-01-01
    • 2016-09-07
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-14
    • 2020-04-25
    • 1970-01-01
    相关资源
    最近更新 更多