Skip to content

noEvolvingAny (since v1.6.3)

Diagnostic Category: lint/nursery/noEvolvingAny

Disallow variables from evolving into any type through reassignments.

In TypeScript, variables without explicit type annotations can evolve their types based on subsequent assignments. This behaviour can accidentally lead to variables with an any type, weakening type safety. Just like the any type, evolved any types disable many type-checking rules and should be avoided to maintain strong type safety. This rule prevents such cases by ensuring variables do not evolve into any type, encouraging explicit type annotations and controlled type evolutions.

let a;
nursery/noEvolvingAny.js:1:5 lint/nursery/noEvolvingAny ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This variable's type is not allowed to evolve implicitly, leading to potential any types.
  
  > 1 │ let a;
       ^
    2 │ 
  
   The variable's type may evolve, leading to any. Use explicit type or initialization. Specifying an explicit type or initial value to avoid implicit type evolution.
  
const b = [];
nursery/noEvolvingAny.js:1:7 lint/nursery/noEvolvingAny ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This variable's type is not allowed to evolve implicitly, leading to potential any types.
  
  > 1 │ const b = [];
         ^
    2 │ 
  
   The variable's type may evolve, leading to any. Use explicit type or initialization. Specifying an explicit type or initial value to avoid implicit type evolution.
  
let c = null;
nursery/noEvolvingAny.js:1:5 lint/nursery/noEvolvingAny ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This variable's type is not allowed to evolve implicitly, leading to potential any types.
  
  > 1 │ let c = null;
       ^
    2 │ 
  
   The variable's type may evolve, leading to any. Use explicit type or initialization. Specifying an explicit type or initial value to avoid implicit type evolution.
  
let a: number;
let b = 1;
var c : string;
var d = "abn";
const e: never[] = [];
const f = [null];
const g = ['1'];
const h = [1];
let workspace: Workspace | null = null;