microsoft / microsoft/typespec
Should empty unions be treated as `never`
Open
design:needed
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
The TypeSpec `union Foo { }` should be semantically equivalent to `never`. Emitters could handle this special case, but we could also consider alternative approaches:
* `union Foo { }` behaves like `declare Foo = never` (using the hypothetical `declare` feature we discussed as a way to emit and decorate an alias).
* Provide an API like `reduceUnion` which does subtype reduction on the union - we do this for union literals, but not for union statements, so this API may be useful to get subtype-reduced union declarations. The API would return `never` for an empty union.
Contributor guide
Assessment
This issue has not been assessed yet.