noNonNullAssertion
Ta treść nie jest jeszcze dostępna w Twoim języku.
Summary
Section titled “Summary”- Rule available since: 
v1.0.0 - Diagnostic Category: 
lint/style/noNonNullAssertion - This rule is recommended, which means is enabled by default.
 - This rule has an unsafe fix.
 - The default severity of this rule is warning.
 - Sources:
 
How to configure
Section titled “How to configure”{  "linter": {    "rules": {      "style": {        "noNonNullAssertion": "error"      }    }  }}Description
Section titled “Description”Disallow non-null assertions using the ! postfix operator.
TypeScript’s ! non-null assertion operator asserts to the type system that an expression is non-nullable, as
in not null or undefined. Using assertions to tell the type system new information is often a sign that
code is not fully type-safe. It’s generally better to structure program logic so that TypeScript understands
when values may be nullable.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”interface Example {  property?: string;}declare const foo: Example;const includesBaz = foo.property!.includes('baz');code-block.ts:5:21 lint/style/noNonNullAssertion  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Forbidden non-null assertion.
  
    3 │ }
    4 │ declare const foo: Example;
  > 5 │ const includesBaz = foo.property!.includes(‘baz’);
      │                     ^^^^^^^^^^^^^
    6 │ 
  
  ℹ Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator
  
    3 3 │   }
    4 4 │   declare const foo: Example;
    5   │ - const·includesBaz·=·foo.property!.includes(‘baz’);
      5 │ + const·includesBaz·=·foo.property?.includes(‘baz’);
    6 6 │   
  
(b!! as number) = "test";code-block.ts:1:2 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Forbidden non-null assertion.
  
  > 1 │ (b!! as number) = “test”;
      │  ^^^
    2 │ 
  
interface Example {  property?: string;}
declare const foo: Example;const includesBaz = foo.property?.includes('baz') ?? false;Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.