-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Disallow overriding a required property with an optional prope…
…rty (#3659) 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. --------- Co-authored-by: Will Temple <[email protected]>
- Loading branch information
1 parent
fe345f2
commit 859f792
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
.chronus/changes/witemple-no-override-required-as-optional-2024-5-25-14-39-2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
changeKind: breaking | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters