Skip to content

⬅️ Back to Table of Contents

📄 nullThrows

📊 Analysis Summary

Metric Count
🔧 Functions 2
📊 Variables & Constants 1

📚 Table of Contents

🛠️ File Location:

📂 packages/utils/src/eslint-utils/nullThrows.ts

Variables & Constants

Name Type Kind Value Exported
NullThrowsReasons { readonly MissingParent: "Expected n... const { MissingParent: 'Expected node to have a parent.', MissingToken: (token: str...

Functions

MissingToken(token: string, thing: string): string

Parameters:

  • token string
  • thing string

Returns: string

Code
(token: string, thing: string) =>
    `Expected to find a ${token} for the ${thing}.`

nullThrows(value: T, message: string): NonNullable<T>

Assert that a value must not be null or undefined. This is a nice explicit alternative to the non-null assertion operator.

Raw JSDoc
/**
 * Assert that a value must not be null or undefined.
 * This is a nice explicit alternative to the non-null assertion operator.
 */
Code
export function nullThrows<T>(value: T, message: string): NonNullable<T> {
  if (value == null) {
    throw new Error(`Non-null Assertion Failed: ${message}`);
  }

  return value;
}

Generated by Syntax Scribe