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

no-restricted-property-access: handle used-before-assigned of class properties in initializer and constructor #741

Open
ajafff opened this issue Jan 9, 2021 · 1 comment

Comments

@ajafff
Copy link
Member

ajafff commented Jan 9, 2021

class C {
    prop: string;
    other = this['prop']; // this should be a finding

    constructor(){
        console.log(this.prop); // this is an error
        console.log(this['prop']); // this should be a finding
        this.prop = '';
    }
}

The one in the property initializer should be pretty easy.

Note that checking the use in the constructor needs a complete control flow graph to check for assignments in all possible control flow graphs like o?.[this.prop = ''].prop ?? (this.prop = '');

@ajafff
Copy link
Member Author

ajafff commented Jan 9, 2021

Another special case in property initializer regarding parameter properties:

//@target: ESnext
// @useDefineForClassFields: true
class C {
    prop = this.obj; // error on 'obj'
    constructor(private obj: any) {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant