Skip to content

TypeScript 2.4.1 - TS2345 - "Property 'push' is missing in type #16802

Description

@simonua

TypeScript Version: 2.4.1

I will preface this with me being unclear whether this is a bug or my misunderstanding of the error (more likely), but I hope I can get some traction on it here nevertheless, please. And, thank you!

Code

This code used to work with 2.3.4 but fails in 2.4.1

// A *self-contained* demonstration of the problem follows...
module app {
    class TypeScript24Controller {
        static $inject = ['$log'];

        constructor(private $log: ng.ILogService) {
            $log.debug('TypeScript24Controller constructor called.');
        }
    }

    angular.module('app').controller('TypeScript24Controller', TypeScript24Controller);
}

Stripping private in my constructor eliminates the error, but I do want the private property created.

module app {
    class TypeScript24Controller {
        static $inject = ['$log'];

        constructor($log: ng.ILogService) {
            $log.debug('TypeScript24Controller constructor called.');
        }
    }

    angular.module('app').controller('TypeScript24Controller', TypeScript24Controller);
}

image

Activity

  1. simonua commented on Jun 28, 2017

    @simonua
    Author

    Andy (Andrewkraft) (@Andy-MS), I think that will push me to Angular 1.6 type definitions, but we only run Angular 1.5 (Angular did not use semver back then, and we've encountered some issues with 1.6). Alternatively to upgrading type definitions, is it possible to explicitly turn of weak type checking?

  2. simonua commented on Jun 28, 2017

    @simonua
    Author

    Andy (Andrewkraft) (@Andy-MS), Reading fully through #16047, it looks like there may not be an option to explicitly turn off the check and it's more of a "press forward and fix" approach. However, there appears to be an out with a cast. Turning

    angular.module('app').controller('TypeScript24Controller', TypeScript24Controller);

    into

    angular.module('app').controller('TypeScript24Controller', TypeScript24Controller as any);

    silences the error. I understand that that may be masking it, but it would also be somewhat inconsequential for me in this particular instance, I believe.

  3. simonua commented on Jun 28, 2017

    @simonua
    Author

    Andy (Andrewkraft) (@Andy-MS), ah ok, so simply by introducing one (perhaps inconsequential), non-optional property or method in the interface to mark the type as non-weak, we get by the new weak type check in 2.4? Good to know. Would you say my approach is fair for the use-case I have? Looking for small, yet workable changes. And thanks again for all the info!

  4. simonua commented on Jun 28, 2017

    @simonua
    Author

    Totally valid point. I'll experiment with both approaches and see what ends up being preferable until we can do an angular/typings upgrade. As these are both valid workarounds, I will close this issue. Many thanks, Andy (Andrewkraft) (@Andy-MS)!

  5. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions