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

[core] Disallow overriding a required property with an optional property #3659

Conversation

witemple-msft
Copy link
Member

Closes #3539

This change disallows overriding a required inherited property with an optional property.

This error does not take precedence over regular property assignability rules. In case the property both is optional when the overridden property is required and has a non-assignable type, both errors will be reported.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Jun 25, 2024

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - breaking ✏️

Disallows overriding a required inherited property with an optional property.,> ,> In previous versions of TypeSpec, it was possible to override a required property with an optional property. This is no longer allowed. This change may result in errors in your code if you were relying on this bug, but specifications that used this behavior are likely to have been exposed to errors resulting from incoherent type checking behavior.,> ,> The following example demonstrates the behavior that is no longer allowed:,> ,> tsp,> model Base {,> example: string;,> },> ,> model Child extends Base {,> example?: string;,> },> ,> ,> In this example, the Child model overrides the example property from the Base model with an optional property. This is no longer allowed.

@azure-sdk
Copy link
Collaborator

You can try these changes at https://cadlplayground.z22.web.core.windows.net/prs/3659/

Check the website changes at https://tspwebsitepr.z22.web.core.windows.net/prs/3659/

@witemple-msft
Copy link
Member Author

Merging and will keep an eye on typespec-next to validate that there are no spec errors.

@witemple-msft witemple-msft added this pull request to the merge queue Jul 10, 2024
Merged via the queue into microsoft:main with commit 859f792 Jul 10, 2024
22 checks passed
@witemple-msft witemple-msft deleted the witemple/no-override-required-as-optional branch July 10, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:core Issues for @typespec/compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model extends another allow property to become optional
5 participants