Skip to main content

js/noImportAssign

disallow assigning to imported bindings

ESLint Equivalent: no-import-assign

Examples

Invalid

import x from 'y';
x=1;

 file.ts:2 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2x=1;
     ^

  Use a local variable instead of reassigning an import.


import x from 'y';
[x]=1;

 file.ts:2:1 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2[x]=1;
      ^

  Use a local variable instead of reassigning an import.


import x from 'y';
({x}=1);

 file.ts:2:2 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2({x}=1);
       ^

  Use a local variable instead of reassigning an import.


import x from 'y';
x++

 file.ts:2 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2x++
     ^

  Use a local variable instead of reassigning an import.


import x from 'y';
[...x]=1;

 file.ts:2:4 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2[...x]=1;
         ^

  Use a local variable instead of reassigning an import.


import x from 'y';
({...x}=1);

 file.ts:2:5 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2({...x}=1);
          ^

  Use a local variable instead of reassigning an import.


import x from 'y';
for (x in y);

 file.ts:2:5 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2for (x in y);
          ^

  Use a local variable instead of reassigning an import.


import x from 'y';
x+=1

 file.ts:2 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import x from 'y';
  > 2x+=1
     ^

  Use a local variable instead of reassigning an import.


import * as x from 'y';
x=1;

 file.ts:2 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import * as x from 'y';
  > 2x=1;
     ^

  Use a local variable instead of reassigning an import.


import {x} from 'y';
x=1;

 file.ts:2 lint/js/noImportAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The imported variable x is read-only.

    1import {x} from 'y';
  > 2x=1;
     ^

  Use a local variable instead of reassigning an import.