Skip to content

Correct AuthorizationError field declarations for ES 2022 #24405

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

Merged
merged 4 commits into from
Apr 22, 2025

Conversation

CraigMacomber
Copy link
Contributor

Description

Fix AuthorizationError.claims and AuthorizationError.tenantId so they don't shadow the actual values from the super constructor that are manually copied onto the this object when TypeScript introduces an ES6 class fields by targeting ES 2022.

Issue detected by #24324

Reviewer Guidance

The review process is outlined on this wiki page.

@Copilot Copilot AI review requested due to automatic review settings April 18, 2025 22:17
@github-actions github-actions bot added the area: loader Loader related issues label Apr 18, 2025
@github-actions github-actions bot added the base: main PRs targeted against main branch label Apr 18, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue where class fields from the super constructor are unintentionally overridden when targeting ES 2022, by updating the property declarations in AuthorizationError.

  • Replaces standard field declarations with TypeScript's "declare" syntax for claims and tenantId.
  • Adds comments explaining the change to prevent field overriding.

CraigMacomber and others added 2 commits April 18, 2025 15:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment on lines 117 to 118
// When targeting ES 2022 or later, TypeScript generates ES6 class fields for these properties.
// This overrides the own properties dynamically created by the super constructor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo - perhaps you mean to omit "own"

But might warrant some rewording. I think you mean to say that readonly claims?: string would override super class properties. It is hard to understand because now it says declare ... which does not have that behvior.

Maybe something like:
When targeting ES 2022 or later, TypeScript generates ES6 class fields for properties listed without declare keyword and overrides the properties dynamically created by the super constructor.

Or just leave it out and amend the following to say:
To prevent undesired overriding of super class properties (when targeting ES 2022 or later),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically mean "own properties" (the same "own properties" in APIs like "Object.getOwnPropertyNames").

I specifically mentioned this, since overriding inherited properties is much more common and easier, but not what is being done here.

How about:

Suggested change
// When targeting ES 2022 or later, TypeScript generates ES6 class fields for these properties.
// This overrides the own properties dynamically created by the super constructor.
// When targeting ES 2022 or later, TypeScript would generate ES6 class fields for these properties if they did not use "declare".
// That would override the own properties dynamically created in the super constructor
// resulting in these properties always holding `undefined` instead of their desired values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is more clear: Does that address your concerns?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revision works. The difficulty is just English. "the own properties" looks like a "their own properties" because "their own" is an extremely common phrase. Putting "own" in quotes would have helped make it look intentional.

CraigMacomber added a commit that referenced this pull request Apr 18, 2025
## Description

Ensure these tests would fail if error was not thrown, make a bit more
concise.

Cleanup done while working on
#24405
@CraigMacomber CraigMacomber merged commit 643d877 into microsoft:main Apr 22, 2025
37 checks passed
@CraigMacomber CraigMacomber deleted the AuthorizationErrorEs2022 branch April 22, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: loader Loader related issues base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants