microsoft / microsoft/typespec

Should empty unions be treated as `never`

Open
#2,201 1 comment 1 reaction 0 assignees View on GitHub
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

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.