microsoft / microsoft/typespec

Should `|` in a union declaration be equivalent to a `,`

Open
#7,523 1 comment 1 reaction 0 assignees View on GitHub
compiler:core feature needs-area triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

Seen a few people mistakely use `|` in a union declaration cause it actually create a nested union expression inside

```tsp
union Foo {
string,
int32 | int8,
}
```

```yaml
Foo:
anyOf:
- type: string
- anyOf:
- type: integer
format: int32
- type: integer
format: int8

```
[Playground Link](https://typespec.io/playground/?c=dW5pb24gRm9vIHsKICBzdHJpbmcsCiAgaW50MzIgfMQIOCwKfQo%3D&e=%40typespec%2Fopenapi3&options=%7B%7D)

Feels like is highly likely this is a user error and allowing that would allow the formatter to fix it. If someone really wants to do that they could force wrap it with `()`

```tsp
union Foo {
string,
(int32 | int8),
}
```

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.