# @typescript-eslint/no-type-alias

> Disallow `type` aliases, or allow only some kinds of them

Some teams want object shapes written as `interface` and other types written out where they're used. This rule bans `type` aliases, and its options allow the kinds you still need.

With no options, every `type` declaration is reported. In a union or an intersection, each member is reported separately.

typescript-eslint has deprecated this rule.

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
type UserId = string;

type User = {
  id: string;
};

type OnSave = (user: User) => void;
```

Not reported:

{/* good */}
```ts
interface User {
  id: string;
}

interface OnSave {
  (user: User): void;
}
```

## Options

Each option allows one kind of alias. It's `"never"` (default) or `"always"`.

| Option | What it allows |
| --- | --- |
| `allowAliases` | Another name for a type: `type Id = string`, `type Mode = "on"`, `type Ids = string[]`, `type Keys = keyof User`. |
| `allowLiterals` | Object types: `type User = { id: string }`. |
| `allowMappedTypes` | Mapped types: `type Flags = { [K in Keys]: boolean }`. |
| `allowTupleTypes` | Tuples: `type Point = [number, number]`. |
| `allowCallbacks` | Function types: `type OnSave = () => void`. |
| `allowConstructors` | Constructor types: `type Ctor = new () => User`. |
| `allowConditionalTypes` | Conditional types: `type Item<T> = T extends (infer U)[] ? U : T`. |
| `allowGenerics` | A type with type arguments: `type Users = Map<string, User>`. |

The first four also take `"in-unions"`, `"in-intersections"` and `"in-unions-and-intersections"`. These allow that kind only as a member of a union, of an intersection, or of either.

A common setup allows unions of names and literals, which an `interface` can't express:

{/* good {"options": [{"allowAliases": "in-unions"}]} */}
```ts
type Status = "draft" | "published" | "archived";
```

An alias that isn't a union is still reported:

{/* bad {"options": [{"allowAliases": "in-unions"}]} */}
```ts
type Status = "draft";
```

## When not to use it

Most TypeScript code uses aliases for unions, tuples, mapped types and conditional types, which you can't write any other way. If you only want `interface` instead of `type` for object shapes, use `@typescript-eslint/consistent-type-definitions`.
