-
Notifications
You must be signed in to change notification settings - Fork 12.8k
allow access protected member in this parameter context #24645
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
Conversation
src/compiler/checker.ts
Outdated
return false; | ||
let thisParameter: ParameterDeclaration | undefined; | ||
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false); | ||
if (!thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is kind of weird that this works for static properties without this.
. i think we should prohibit this. e.g.:
class C {
protected static S = 0;
}
C.S; // Error
function f(this: C) {
C.S; // OK
}
@weswigham can you please review this change. |
src/compiler/checker.ts
Outdated
// static member access is disallow | ||
let thisParameter: ParameterDeclaration | undefined; | ||
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false); | ||
if (flags & ModifierFlags.Static || !thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. i would move the check for the flag above the request for getThisContainer
this PR take a simple implement
ThisParameter
when cannot findenclosingClass
in protected accessibility checkConstraint
if typeof this is generic parameterFixes #10302