Skip to content

Conversation

@Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Jun 4, 2018

this PR take a simple implement

  • lookup ThisParameter when cannot find enclosingClass in protected accessibility check
  • get Constraint if typeof this is generic parameter

Fixes #10302

return false;
let thisParameter: ParameterDeclaration | undefined;
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
if (!thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) {
Copy link
Contributor

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
}

@mhegazy mhegazy requested a review from weswigham June 4, 2018 17:36
@mhegazy
Copy link
Contributor

mhegazy commented Jun 4, 2018

@weswigham can you please review this change.

// 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) {
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants