or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-types--warning

TypeScript definitions for the warning library - a mirror of Facebook's warning utility for logging development-time warnings when conditions are not met

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@types/warning@3.0.x

To install, run

npx @tessl/cli install tessl/npm-types--warning@3.0.0

index.mddocs/

Warning

TypeScript definitions for the warning library - a mirror of Facebook's warning utility for logging development-time warnings when conditions are not met. The warning library enables developers to conditionally log warnings to help with debugging and development, designed to be stripped from production builds.

Package Information

  • Package Name: @types/warning
  • Package Type: npm (TypeScript definitions)
  • Language: TypeScript
  • Installation: npm install @types/warning
  • Original Library: npm install warning

Core Imports

import warning = require("warning");

For projects with module resolution:

import * as warning from "warning";

Basic Usage

import warning = require("warning");

// Warning when condition is falsy - logs to console.error
warning(false, "This will show a warning message");

// No warning when condition is truthy
warning(true, "This will not show a warning");

// Warning with formatted message and extra parameters
warning(false, "User %s has invalid age: %d", "Alice", -5);

// Common usage patterns
const isValidUser = user && user.name && user.age > 0;
warning(isValidUser, "Invalid user object provided to UserComponent");

const isProduction = process.env.NODE_ENV === "production";
warning(!isProduction, "Debug mode enabled - performance may be affected");

Architecture

The warning library implements a simple functional architecture pattern:

  • Single Function Export: The entire library exports one utility function using CommonJS pattern (export = warning)
  • Conditional Logging: Core logic evaluates a condition and logs to console.error() when falsy
  • Development-Focused: Designed for development-time debugging with production stripping in mind
  • Format String Support: Uses printf-style format strings for message interpolation
  • Zero Dependencies: Lightweight utility with no external dependencies

Capabilities

Warning Function

Conditionally logs warning messages to console.error when a condition is not met. Designed for development-time debugging and should be stripped from production builds using tools like babel-plugin-dev-expression.

/**
 * Conditionally logs a warning message when condition is falsy
 * @param condition - The condition to check (any falsy value triggers warning)
 * @param format - Optional warning message format string
 * @param extra - Additional arguments for formatted message
 * @returns void
 */
declare const warning: (condition: any, format?: string, ...extra: any[]) => void;

Parameters:

  • condition (any): Condition to evaluate - warning is logged when falsy (false, 0, "", null, undefined, etc.)
  • format (optional string): Warning message or format string for additional parameters
  • ...extra (rest parameters, any[]): Additional arguments used with format string for message interpolation

Behavior:

  • Logs to console.error() (not console.warn()) when condition is falsy
  • Silent when condition is truthy
  • Supports printf-style format strings with additional parameters
  • Intended for development environments only
  • Should be removed from production builds using babel-plugin-dev-expression

Usage Examples:

// Basic conditional warning
warning(user.isValid, "User validation failed");

// Warning with interpolated values
warning(age >= 18, "Age %d is below minimum required age", age);

// Object validation
warning(
  config && typeof config.apiKey === "string",
  "Configuration missing required apiKey property"
);

// Development environment checks
warning(
  process.env.NODE_ENV !== "production",
  "Performance debugging enabled in production environment"
);

Development Context

This warning utility is specifically designed for development-time debugging:

  • Development Usage: Log conditional warnings to help identify potential issues
  • Production Stripping: Use babel-plugin-dev-expression to remove warnings from production builds
  • Console Output: Uses console.error() instead of console.warn() for consistency with Facebook's original implementation
  • Performance: No performance impact in production when properly stripped
  • Debugging: Ideal for component validation, configuration checks, and development assertions

Export Pattern

The package uses CommonJS export pattern:

export = warning;

This requires the import syntax:

import warning = require("warning");