Skip to content

The | and & operators are ignored before the first element #3394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ printId("202");
printId({ myID: 22342 });
```

> The separator of the union members is allowed before the first element, so you could also write this:
> The `|` operator is ignored when used before the first element, so you could also write this:
> ```ts twoslash
> function printTextOrNumberOrBool(
> textOrNumberOrBool:
Expand Down
14 changes: 14 additions & 0 deletions packages/documentation/copy/en/handbook-v2/Object Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ draw({ color: "blue", radius: 42 });
draw({ color: "red", raidus: 42 });
```

> The `&` operator is ignored when used before the first element, so you could also write this:
> ```ts twoslash
> function draw(
> circle:
> & Colorful
> & Circle
> & Coordinates
> ) {
> console.log(`Color was ${circle.color}`);
> console.log(`Radius was ${circle.radius}`);
> console.log(`Coordinates was ${circle.coordinates}`);
> }
> ```

## Interface Extension vs. Intersection

We just looked at two ways to combine types which are similar, but are actually subtly different.
Expand Down