Skip to content
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

chore: add undefined type to principalAccount #33055

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dali546
Copy link
Contributor

@dali546 dali546 commented Jan 22, 2025

Reason for this change

When using TypeScript option exactOptionalPropertyTypes: truewe get the following error. All implementations ofIPrincipalhave the typestring | undefined` so this is change will apply it at the base

Type 'AccountPrincipal' is not assignable to type 'IPrincipal' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'principalAccount' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.ts(2375)

Description of changes

Changed type definition of IPrincipal principalAccount

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Jan 22, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 22, 2025 11:34
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Jan 22, 2025
@dali546 dali546 force-pushed the undefined-principalAccount branch from db6bb3a to f0d99ef Compare January 22, 2025 11:34
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.24%. Comparing base (48ae4d0) to head (dcda22d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33055   +/-   ##
=======================================
  Coverage   82.24%   82.24%           
=======================================
  Files         119      119           
  Lines        6875     6875           
  Branches     1161     1161           
=======================================
  Hits         5654     5654           
  Misses       1118     1118           
  Partials      103      103           
Flag Coverage Δ
suite.unit 82.24% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.24% <ø> (ø)
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 22, 2025
@lpizzinidev
Copy link
Contributor

Hi @dali546
It seems that this PR raised a similar issue a while ago. The related discussion is still open.
I guess that general guidance should be provided for type declarations of | undefined / ?: props.
@kaizencc Thoughts?

@GavinZZ GavinZZ self-assigned this Feb 26, 2025
@GavinZZ
Copy link
Contributor

GavinZZ commented Feb 27, 2025

@lpizzinidev @dali546 thanks for the PR. I added some new update in the discussion post #23885 (comment).

Can you let me know your use case of the IPrincipal variable and if you can use the workaround mentioned. I'm happy to have this merged if the workaround mentioned does not work for you.

@dali546
Copy link
Contributor Author

dali546 commented Mar 6, 2025

@GavinZZ the use case is even just creating simple roles using a principal, it causes the error eg

    const role = new Role(this, "role", {
      assumedBy: new WebIdentityPrincipal("accounts.google.com", {}),
    });
Type 'WebIdentityPrincipal' is not assignable to type 'IPrincipal' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'principalAccount' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.ts(2375)

The proposed workaround of using the spread operator doesn't help here either because principalAccount? is defined inside WebIdentityPrincipal

@dali546 dali546 force-pushed the undefined-principalAccount branch from f0d99ef to dcda22d Compare March 6, 2025 06:57
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: dcda22d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants