microsoft / microsoft/typespec
Self Referencing Generics only work when optional
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
The following TypeSpec Code:
```
model MyModel> {
// otherProperties
link: T;
}
model ExtendsMyModel extends MyModel {
// some other properties
}
```
Throws the following Error:
`error
missing-property
Property 'link' is missing on type 'ExtendsMyModel' but required in 'MyModel'`
[Playground Link](https://cadlplayground.z22.web.core.windows.net/?c=bW9kZWwgTXlNxAg8VCBleHRlbmRzyhI%2BPiB7DQogICAgLy8gb3RoZXJQcm9wZXJ0aWVzxhhsaW5rOiBUOw0KfQ0KDQrGUkXGSMdH0VfOH8djLy8gc29tZcZmIHDLZ30%3D)
Making the link-property optional makes it work though:
```
model MyOptionalModel> {
// otherProperties
link?: T;
}
model ExtendsMyOptionalModel extends MyOptionalModel {
// some other properties
}
```
[Playground Link](https://cadlplayground.z22.web.core.windows.net/?c=bW9kZWwgTXlNxAg8VCBleHRlbmRzyhI%2BPiB7DQogICAgLy8gb3RoZXJQcm9wZXJ0aWVzxhhsaW5rPzogVDsNCn0NCg0KxlNFxknHSNFYzh%2FHZC8vIHNvbWXGZyBwy2h9)
Maybe this has to do with the [warning in the interface docs](https://microsoft.github.io/typespec/next/language-basics/interfaces
)
Contributor guide
Assessment
This issue has not been assessed yet.