Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve docs for ts no-extra-non-null-assertion
  • Loading branch information
therewillbecode committed Mar 8, 2025
commit 7f64f2e144dd343ee0ad9eecfe98562b8fa2bfbc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,48 @@ declare_oxc_lint!(
/// Disallow extra non-null assertions.
///
/// ### Why is this bad?
/// The `!` non-null assertion operator in TypeScript is used to assert that a value's type does not include null or undefined. Using the operator any more than once on a single value does nothing.
///
/// ### Example
/// The `!` non-null assertion operator in TypeScript is used to assert that a value's type
/// does not include null or undefined. Using the operator any more than once on a single value
/// does nothing.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```ts
/// const foo: { bar: number } | null = null;
/// const bar = foo!!!.bar;
/// ```
///
/// ```ts
/// function foo(bar: number | undefined) {
/// const bar: number = bar!!!;
/// }
/// ```
///
/// ```ts
/// function foo(bar?: { n: number }) {
/// return bar!?.n;
/// }
/// ```
///
/// Examples of **correct** code for this rule:
/// ```ts
/// const foo: { bar: number } | null = null;
/// const bar = foo!.bar;
/// ```
///
/// ```ts
/// function foo(bar: number | undefined) {
/// const bar: number = bar!;
/// }
/// ```
///
/// ```ts
/// function foo(bar?: { n: number }) {
/// return bar?.n;
/// }
/// ```
NoExtraNonNullAssertion,
typescript,
correctness
Expand Down
Loading