Skip to content

Conversation

mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Sep 12, 2025

This adds support for the new class-covariant-overrides feature into @jsii/spec.

class-covariant-overrides relaxes the existing restriction on covariant overrides 1. With the feature it is now allowed to override the type of readonly class properties and the return type of class methods when extending other classes, as long as the changes are covariant 2 3 to the superclass. Importantly, covariant overrides are still not allowed when implementing interfaces.

Compilers that are producing assemblies with covariant class overrides MUST include class-covariant-overrides in the usedFeatures set.

This feature does not require any changes to the kernels, runtimes or packmak. All generated code already is already correct when given an appropriate assembly. We can now add support for this feature due to the upgrade to net6.0 4 which was the only thing blocking it.

Proof all of this is working together: #4925


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

Footnotes

  1. https://aws.github.io/jsii/user-guides/lib-author/typescript-restrictions/#covariant-overrides-parameter-list-changes

  2. https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)

  3. As of today this feature strictly applies to class and interface types, event though some built-in types like lists might also be technically covariant.

  4. https://github.com/aws/jsii/pull/4916

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 12, 2025
@mrgrain mrgrain added the pr/do-not-merge This PR should not be merged at this time. label Sep 12, 2025
@mrgrain mrgrain force-pushed the mrgrain/feat/class-covariant-overrides branch from d1ad18e to f05492d Compare September 14, 2025 14:41
@mrgrain mrgrain removed the pr/do-not-merge This PR should not be merged at this time. label Sep 14, 2025
Copy link
Contributor

mergify bot commented Sep 15, 2025

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Sep 15, 2025
Copy link
Contributor

mergify bot commented Sep 15, 2025

Merging (with squash)...

@mergify mergify bot merged commit bac5377 into main Sep 15, 2025
38 checks passed
@mergify mergify bot deleted the mrgrain/feat/class-covariant-overrides branch September 15, 2025 07:04
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants