Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
simonua opened this issue Jun 28, 2017 · 7 comments
Closed

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

simonua opened this issue Jun 28, 2017 · 7 comments

Comments

@simonua
Copy link

simonua commented Jun 28, 2017

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

@ghost
Copy link

ghost commented Jun 28, 2017

This is due to new weak type checking (#16047).
Should have been fixed by DefinitelyTyped/DefinitelyTyped#17303. Try upgrading your @types/angular?

@simonua
Copy link
Author

simonua commented Jun 28, 2017

@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?

@ghost
Copy link

ghost commented Jun 28, 2017

No, but you could use a similar fix to the one in DefinitelyTyped/DefinitelyTyped#17303; augment the interface with an index signature.

interface Options {
    a?: number;
    b?: number;
}

// Won't compile without this
interface Options {
    [x: string]: any;
}

class C {}
const options: Options = C;

@simonua
Copy link
Author

simonua commented Jun 28, 2017

@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.

@simonua
Copy link
Author

simonua commented Jun 28, 2017

@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!

@ghost
Copy link

ghost commented Jun 28, 2017

Either is fine, although as any is less safe as your types won't be checked if you try to implement any of IController's optional methods.

@simonua
Copy link
Author

simonua commented Jun 28, 2017

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-ms!

@simonua simonua closed this as completed Jun 28, 2017
kdcllc added a commit to kdcllc/Chavah that referenced this issue Dec 18, 2017
….6 upgrade occured (microsoft/TypeScript#16802)

2. add routes info to the test controller.
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant