microsoft / microsoft/typespec

Nominal types in TypeSpec

Open
#3,900 0 comments 0 reactions 0 assignees View on GitHub
compiler:core design:needed triaged:core
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.