Skip to main content


Require destructuring from arrays and/or objects.


Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.


This rule requires type information to run.


This rule extends the base eslint/prefer-destructuring rule. It adds support for TypeScript's type annotations in variable declarations.

const x: string = obj.x; // This is incorrect and the auto fixer provides following untyped fix.
// const { x } = obj;
Open in Playground

And it infers binding patterns more accurately thanks to the type checker.

const x = ['a'];
const y = x[0];
Open in Playground

How to Use

module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"prefer-destructuring": "off",
"@typescript-eslint/prefer-destructuring": "error"
Try this rule in the playground ↗


See eslint/prefer-destructuring options.

This rule adds the following options:

type Options = [
BasePreferDestructuringOptions[1] & {
enforceForDeclarationWithTypeAnnotation?: boolean;

const defaultOptions: Options = [
enforceForDeclarationWithTypeAnnotation: false,


When set to true, type annotated variable declarations are enforced to use destructuring assignment.

Examples with { enforceForDeclarationWithTypeAnnotation: true }:

const x: string = obj.x;
Open in Playground


Taken with ❤️ from ESLint core