Skip to content

@loontail/minecraft-kit v0.8.14 / assertNever

Function: assertNever()

ts
function assertNever(value): never

Exhaustiveness sentinel for discriminated unions. Drop into the default of a switch on kind / type / status so the compiler errors when a new variant is added but the switch is not updated.

Parameters

ParameterType
valuenever

Returns

never

Example

ts
import { assertNever, InstallActionKinds, type InstallAction } from "@loontail/minecraft-kit";

function describe(action: InstallAction): string {
  switch (action.kind) {
    case InstallActionKinds.DOWNLOAD_FILE: return `download ${action.target}`;
    case InstallActionKinds.EXTRACT_NATIVE: return `extract ${action.source}`;
    case InstallActionKinds.WRITE_VERSION_JSON: return `write ${action.target}`;
    case InstallActionKinds.WRITE_LOGGING_CONFIG: return `write ${action.target}`;
    case InstallActionKinds.RUN_FORGE_PROCESSOR: return `processor ${action.processor.jar}`;
    default: return assertNever(action);
  }
}

Source

src/core/assert-never.ts:22

MIT License