microsoft / microsoft/typespec
Nominal types in TypeSpec
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
As part of this issue https://github.com/microsoft/typespec/issues/2737 there is cases where some strongly typed language would like to be able to define a strong relation between models. The approach of using `extends` vs `satisfies` doesn't really work well for all cases as well as being a breaking change
Some idea is having a modifier on models to be able to define them as nominal
```
nom model Foo {
name: string;
}
// or
nominal model Bar {
name: string
}
```
Then in any condition where we check if something is assignable to `Bar` it would need to explicitly `extends` it. Matching the structure wouldn't satisfy the constraint
Note that maybe nominal type is not the answer. But as stated above we cannot depend on the constraint keyword to differentiate. We could have a modifier on it `extends nominal Constraint` or `: nominal Constraint`
Contributor guide
Assessment
This issue has not been assessed yet.