# @putout/plugin-declare

> 🐊Putout plugin adds ability to declare variables

Latest version **8.5.0** (published 2026-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @putout/plugin-declare
pnpm add @putout/plugin-declare
yarn add @putout/plugin-declare
bun add @putout/plugin-declare
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 8.5.0 |
| Published | 2026-11-25 |
| First published | 2023-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 804 |
| Author | coderaiser |
| Maintainers | coderaiser |
| Keywords | putout, putout-plugin, plugin, declare-undefined-variables |

## Links

- npm: https://www.npmjs.com/package/@putout/plugin-declare
- Repository: https://github.com/coderaiser/putout
- Homepage: https://github.com/coderaiser/putout/tree/master/packages/plugin-declare#readme
- Issues: https://github.com/coderaiser/putout/issues
- npm.io page: https://npm.io/package/@putout/plugin-declare

## Recent versions

- 8.5.0 (latest) — 2026-11-25
- 8.4.0 — 2026-07-15
- 8.3.0 — 2026-06-06
- 8.2.0 — 2026-04-10
- 8.1.0 — 2026-02-22
- 8.0.0 — 2026-02-18
- 7.2.0 — 2026-01-27
- 7.1.0 — 2026-01-11
- 7.0.1 — 2026-01-11
- 7.0.0 — 2026-01-11
- 6.0.0 — 2025-09-14
- 5.0.0 — 2025-02-14
- 4.0.0 — 2024-04-21
- 3.1.0 — 2024-03-22
- 3.0.0 — 2024-02-01
- … 8 more at https://npm.io/package/@putout/plugin-declare/versions

## README

# @putout/plugin-declare [![NPM version][NPMIMGURL]][NPMURL]

[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-declare.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-declare "npm"

🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to declare variable that was not defined before, including:

- [maybe](https://github.com/coderaiser/putout/tree/master/packages/plugin-maybe#readme): `maybeArray`, `maybeFn`, `maybeEmptyArray`;
- wrap: `not`,`id`, `returns`, `callWith`;
- set: `difference`;
- fresh-import: `freshImport`, `freshImportDefault`;
- `fixtures`: `readFixture`;
- properties of `Object`;
- properties of `String` + `addQuotes`;
- [wraptile](https://github.com/coderaiser/wraptile);
- [fullstore](https://github.com/coderaiser/fullstore);
- [currify](https://github.com/coderaiser/currify);
- [pipe-io](https://github.com/coderaiser/pipe-io);
- [pullout](https://github.com/coderaiser/pullout);
- [wait](https://github.com/iocmd/wait);
- [chalk](https://www.npmjs.com/package/chalk);
- [jessy](https://www.npmjs.com/package/jessy);
- [nessy](https://www.npmjs.com/package/nessy);
- [rendy](https://www.npmjs.com/package/rendy);
- [table](https://www.npmjs.com/package/table);

## Install

```
npm i putout @putout/plugin-declare -D
```

Add `.putout.json` with:

```json
{
    "plugins": {
        "declare": "on"
    }
}
```

## Rules

Use options:

- ✅ `dismiss` for variables you don't want to declare;
- ✅ `declarations` to declare variables;

```json
{
    "rules": {
        "declare": ["on", {
            "declarations": {
                "hello": "import {hello} from 'world'"
            },
            "dismiss": [
                "assert",
                "entries",
                "parse",
                "stringify",
                "defineProperty",
                "noop",
                "join",
                "keys",
                "values",
                "stopAll",
                "once",
                "putout"
            ]
        }]
    }
}
```

## `assign`

### ❌ Example of incorrect code

```js
const hello = 'world';
const object = {};

assign(object, {
    hello,
});
```

### ✅ Example of correct code

```js
const hello = 'world';
const object = {};
const {assign} = Object;

assign(object, {
    hello,
});
```

## `keys`

### ❌ Example of incorrect code

```js
const hello = 'world';
const object = {};

const allKeys = keys(object);
```

### ✅ Example of correct code

```js
const hello = 'world';
const object = {};
const {keys} = Object;

const allKeys = keys(object);
```

## `values`

### ❌ Example of incorrect code

```js
const object = {};
const allValues = values(object);
```

## ✅ Example of correct code

```js
const {values} = Object;

const object = {};
const allValues = values(object);
```

## `noop`

### ❌ Example of incorrect code

```js
noop();
```

### ✅ Example of correct code

```js
const noop = () => {};
noop();
```

## Types

### ❌ Example of incorrect code

```js
const isFn = (a) => typeof a === 'function';

if (isFn(fn))
    fn();
```

### ✅ Example of correct code

```js
const isFn = (a) => typeof a === 'function';

if (isFn(fn))
    fn();
```

## Maybe

### ❌ Example of incorrect code

```js
const a = maybeArray(b);
```

### ✅ Example of correct code

```js
const {isArray} = Array;
const maybeArray = (a) => isArray(a) ? a : [a];

const a = maybeArray(b);
```

## `entries`

### ❌ Example of incorrect code

```js
entries([1, 2, 3]);
```

### ✅ Example of correct code

```js
const {entries} = Object;

entries([1, 2, 3]);
```

## `fromEntries`

### ❌ Example of incorrect code

```js
fromEntries(['hello', 'world']);
```

### ✅ Example of correct code

```js
const {fromEntries} = Object;

fromEntries(['hello', 'world']);
```

## `fromCharCode`

### ❌ Example of incorrect code

```js
const encoded = new TextEncoder().encode(str);
fromCharCode(...encoded);
```

### ✅ Example of correct code

```js
const {fromCharCode} = String;
const encoded = new TextEncoder().encode(str);

fromCharCode(...encoded);
```

## License

MIT

---
_Source: https://npm.io/package/@putout/plugin-declare · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
