microsoft / typespec

https://typespec.io/
MIT License
4.57k stars 224 forks source link

Reconsider mixed use of `extends` #3901

Open timotheeguerin opened 4 months ago

timotheeguerin commented 4 months ago

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

Option could be

ArcturusZhang commented 4 months ago

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 commented 4 months ago

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.