Skip to content

Accessing protected property on this-type outside of class body doesn't work for generic classes #36926

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

Closed
ajafff opened this issue Feb 21, 2020 · 0 comments · Fixed by #36928
Labels
Bug A bug in TypeScript
Milestone

Comments

@ajafff
Copy link
Contributor

ajafff commented Feb 21, 2020

TypeScript Version: 3.9.0-dev.20200220

Search Terms:

Code

class Regular {
    protected foo = 1;
}

function regular(this: Regular) {
    this.foo; // works
}

class Generic<T> {
    protected foo = 1;
}

function generic(this: Generic<unknown>) {
    this.foo; // error
}

Expected behavior:

There should be no difference between generic and non-generic classes. Both functions should be allowed to access this.foo.

Actual behavior:

Property 'foo' is protected and only accessible through an instance of class 'Generic<unknown>'.(2446)

Playground Link: http://www.typescriptlang.org/play/?ts=3.9.0-dev.20200220#code/MYGwhgzhAEBKCmBzAruATtA3gKGn6ADmgPYAu8w5AJtAGbHHQC80AjANzYC+22tyAO0oBLYgOhokqMGgAUpABbCIALjhT0ASiy58i5QDp6xdtAD0Z6AHdiaANYRuvUJBgBxeAPhphwADwAKgB8OviEJOSU8DTGzGycPHyCImLQiJ7evvJKqtAeXj7+gnYCxFYCQdo4YfoQRgymFtDeJGjcQA

Related Issues:

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

Successfully merging a pull request may close this issue.

2 participants