-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Error on accessing private property through destructuring assignment, and mark property used #26381
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
… and mark property used
66dc4ee
to
774c6be
Compare
*/ | ||
function checkPropertyAccessibility(node: PropertyAccessExpression | QualifiedName | VariableLikeDeclaration | ImportTypeNode, left: Expression | QualifiedName | ImportTypeNode, type: Type, prop: Symbol): boolean { |
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.
Just checking: are the changes to this function just cleanup or do they actually fix one of the bugs?
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.
One of the parameters changed. We no longer pass in the LHS (since destructuring doesn't have one), we just pass in whether it's a super.
access.
src/compiler/checker.ts
Outdated
else { | ||
// non-shorthand property assignments should always have initializers | ||
return checkDestructuringAssignment(property.initializer, type); | ||
let type: Type | undefined; |
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.
Might be worth extracting this to a function? I think it’s self-contained.
src/compiler/checker.ts
Outdated
const prop = getPropertyOfType(objectLiteralType, text); | ||
if (prop) { | ||
markPropertyAsReferenced(prop, property, rightIsThis); | ||
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop); |
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.
Should you be getting type only if propertyAccessibility doesn't have issues?
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 looks like we normally just call this for the diagnostic and don't change the type, e.g.:
class C { private x!: number; }
const x = new C().x; // Error, but doesn't affect type
x; // number
Fixes #26355 and #26380
Discovered but did not fix #26379