# @typescript-eslint/sort-type-constituents

> Require the members of union and intersection types to be sorted

A long union in no particular order is hard to scan, and a member that's listed twice is easy to miss. This rule keeps the members of `A | B` and `A & B` in a fixed order.

Members are first put in groups, with named types first and `null`, `undefined`, and `void` last. Inside a group they're sorted by their text, ignoring case.

`--fix` sorts the members. If there are comments between them, the fix would delete the comments, so it's a suggestion in your editor instead.

typescript-eslint has deprecated this rule. It recommends `eslint-plugin-perfectionist` instead, which isn't built into `bun lint`.

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
type Status = "open" | "closed" | "merged";
type Id = null | string | UserId;
type Props = WithStyle & WithChildren;
```

Not reported:

{/* good */}
```ts
type Status = "closed" | "merged" | "open";
type Id = UserId | string | null;
type Props = WithChildren & WithStyle;
type Key = "alt" | "Shift";
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `checkUnions` | `true` | Check union types (`\|`). |
| `checkIntersections` | `true` | Check intersection types (`&`). |
| `caseSensitive` | `false` | Compare by character code, so every uppercase letter comes before every lowercase one. |
| `groupOrder` | every group, in the order listed here | The order of the groups: `"named"`, `"keyword"`, `"operator"`, `"literal"`, `"function"`, `"import"`, `"conditional"`, `"object"`, `"tuple"`, `"intersection"`, `"union"`, `"nullish"`. Groups you leave out come last, together. |

Not reported with `groupOrder: ["nullish", "keyword", "named"]`:

{/* good {"options": [{"groupOrder": ["nullish", "keyword", "named"]}]} */}
```ts
type Id = null | string | UserId;
```

Reported with `caseSensitive: true`, because `S` comes before `a`:

{/* bad {"options": [{"caseSensitive": true}]} */}
```ts
type Key = "alt" | "Shift";
```

## When not to use it

The order of an intersection can matter when its members declare the same method with different signatures. Turn off `checkIntersections` if you rely on that.
