# use-type-alias

Rule `sonarjs/use-type-alias`. Type aliases should be used

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1383 by reach, #684 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/use-type-alias` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4323/) |

## Code examples

### Incorrect: the rule reports this

```js
function foo(x:string|null|number) { // Noncompliant
  // ...
}
function bar(x:string|null|number) {
  // ...
}
function zoo(): string|null|number {
  return null;
}
```

### Correct: the rule accepts this

```js
type MyType = string | null | number;

function foo(x: MyType) {
  // ...
}
function bar(x: MyType) {
  // ...
}
function zoo(): MyType {
  return null;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/use-type-alias": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/updated-loop-counter](https://lintradar.dev/rules/sonarjs/updated-loop-counter.md): Loop counters should not be assigned within the loop body
- [sonarjs/vitest-mock-at-module-scope](https://lintradar.dev/rules/sonarjs/vitest-mock-at-module-scope.md): Vi.mock should be declared at module scope
- [sonarjs/updated-const-var](https://lintradar.dev/rules/sonarjs/updated-const-var.md): "const" variables should not be reassigned
- [sonarjs/void-use](https://lintradar.dev/rules/sonarjs/void-use.md): "void" should not be used
- [sonarjs/unverified-hostname](https://lintradar.dev/rules/sonarjs/unverified-hostname.md): Server hostnames should be verified during SSL/TLS connections
- [sonarjs/weak-ssl](https://lintradar.dev/rules/sonarjs/weak-ssl.md): Weak SSL/TLS protocols should not be used

---

Web page: https://lintradar.dev/rules/sonarjs/use-type-alias. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
