codelyzer icon indicating copy to clipboard operation
codelyzer copied to clipboard

no-access-missing-member and extended classes

Open robisim74 opened this issue 9 years ago • 75 comments

Hi Minko,

I don't know if the following problem is related to #190, but if I set the property on the subject to true (as recommended) when I have an extended class I get warnings. For example:

@Component({
    templateUrl: 'signin.component.html'
})

export class SigninComponent extends Signin {
    constructor(public router: Router, public authenticationService: AuthenticationService) {
        super(router, authenticationService);
    ...
    }
}
export class Signin {

    model: any = {};

    errorMessage: string = "";

    constructor(public router: Router, public authenticationService: AuthenticationService) { }
    ...
}

I get the following warnings:

app/account/signin.component.html[11, 59]: The property "model" that you're trying to access does not exist in the class declaration.
app/account/signin.component.html[10, 71]: The property "errorMessage" that you're trying to access does not exist in the class declaration.

Packages: "codelyzer": "2.0.0-beta.3", "tslint": "4.0.2", "typescript": "2.0.10"

Note that up to codelyzer 2.0.0-beta.1 I didn't get any error.

Thanks,

Roberto

robisim74 avatar Dec 13 '16 21:12 robisim74

Since recently Angular didn't support metadata for inheritance so this issue was low priority. Probably I will work on it as part of the next release.

mgechev avatar Dec 13 '16 21:12 mgechev

@mgechev I think you missed https://github.com/angular/angular/commit/f5c8e09 since 2.3

aitboudad avatar Dec 16 '16 17:12 aitboudad

Yes, I said "didn't", this is the reason the issue is still open :-)

mgechev avatar Dec 16 '16 18:12 mgechev

Is there any workaround to ignore these?

karlhiramoto avatar Jan 04 '17 23:01 karlhiramoto

I'll work on this during the weekend. Hopefully, by Monday we'll have these working:

Imported base class

// base.ts
class Base {
  bar;
}
// child.ts
import { Base } from './base';

@Component({
  selector: 'child',
  template: '{{ bar }}'
})
class Child extends Base {}

Base class declared in the same file

class Base {
  bar;
}

@Component({
  selector: 'child',
  template: '{{ bar }}'
})
class Child extends Base {}

mgechev avatar Jan 05 '17 09:01 mgechev

@mgechev Thanks!

robisim74 avatar Jan 07 '17 20:01 robisim74

@mgechev not sure if this has to be part of this issue. I have disabled tslinting in html for the whole file:

image

But still getting this error:

The property "message" that you're trying to access does not exist in the class declaration.

Note: message is a base class property of this component.

So, shouldn't disabling override any other check?

asadsahi avatar Jan 14 '17 21:01 asadsahi

@asadsahi You have to disable the rule/tslint in the component (typescript file), not the template.

saithis avatar Jan 14 '17 22:01 saithis

@saithis Thanks. sorted. :)

asadsahi avatar Jan 14 '17 23:01 asadsahi

Excuse me for the delay. There were a lot of things on my plate. I'll try to come up with a fix in the next a couple of days/week.

mgechev avatar Jan 23 '17 22:01 mgechev

@mgechev I'm having this issue now. Any progress on this?

willwlwang avatar Feb 09 '17 00:02 willwlwang

@mgechev @wlngwang as a workaround while this issue is resolved, you can use this['your_prop_name'] in your template. Not ideal, but it gets the warning out of the way for now.

class Base {
  bar;
}

@Component({
  selector: 'child',
  template: '{{ this["bar"] }}'
})
class Child extends Base {}

guojenman avatar Feb 09 '17 00:02 guojenman

@guojenman Thanks. Another workaround could be setting up a proxy property in the child class to return the desired property.

willwlwang avatar Feb 09 '17 00:02 willwlwang

I'm doing this (redeclaring the var) but it's quite annoying :(

Shahor avatar Feb 10 '17 12:02 Shahor

I've been working on ngast for better metadata extraction.

Tomorrow I'll reuse the TypeChecker with program aware walkers, to find the base classes and all symbols. Setting it as a todo item in Things! 👨‍💻

Related to https://github.com/mgechev/codelyzer/issues/64.

mgechev avatar Feb 11 '17 01:02 mgechev

What is the tslint property to disable this check for time being?

mpetkov avatar Feb 11 '17 09:02 mpetkov

What is the tslint property to disable this check for time being?

no-access-missing-member?

khoden avatar Feb 14 '17 11:02 khoden

@guojenman your workaround worked for me. Was not just a property but a method.

class Base {
  bar(arg){return 'x'};
}

@Component({
  selector: 'child',
  template: '{{ this["bar"](arg) }}'
})
class Child extends Base {}

adamgorIBM avatar Feb 14 '17 21:02 adamgorIBM

Good news! Just pushed code which introduces support for extended classes. You can find it here.

I will release 2.0.1 once I make sure everything works properly.

mgechev avatar Feb 19 '17 00:02 mgechev

Btw, if you see any test cases which may fail, please comment in the issue.

mgechev avatar Feb 19 '17 03:02 mgechev