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

Reconsider mixed use of extends #3901

Open
timotheeguerin opened this issue Jul 18, 2024 · 2 comments
Open

Reconsider mixed use of extends #3901

timotheeguerin opened this issue Jul 18, 2024 · 2 comments
Labels
compiler:core Issues for @typespec/compiler design:needed A design request has been raised that needs a proposal triaged:core
Milestone

Comments

@timotheeguerin
Copy link
Member

timotheeguerin commented Jul 18, 2024

In relation to the nominal type proposal #3900 our current mixed use of extends is confusing

  • model extends: Means inheritence
  • interface extends: Means spread operations
  • Template constraint extends means constraint satisfies

Option could be

  • model extends: Keep
  • interface extends: Replace with spread
  • Template constraint extends: replace with : model Foo<T: string>
@ArcturusZhang
Copy link
Member

model extends: Means inheritence

I think this statement only holds true when there is a discriminator from the spec's perspective?
If we only write

model Foo extends Bar {};
op test(@body body: Bar): void;

I think the spec should only be expecting the payload to be Bar and extra properties should be rejected by the service.
At least our current usage calculation in TCGC works in this way.

@timotheeguerin
Copy link
Member Author

extends does create this explicit relation between the 2 models it doesn't have much to do with discriminator in the base language. Docs. I'd expect that every language that support inheritance to keep that relation. Of course if you try to send/return the base model then without a discriminator there isn't a good way to discriminate which child but that can still be used to organize your types.

@markcowl markcowl added design:needed A design request has been raised that needs a proposal compiler:core Issues for @typespec/compiler labels Jul 22, 2024
@markcowl markcowl added this to the Backlog milestone Jul 22, 2024
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 design:needed A design request has been raised that needs a proposal triaged:core
Projects
None yet
Development

No branches or pull requests

3 participants