Type alias TypeErr<S>

TypeErr<S>: {
    [___error]: S;
}

Represents some type-level error which forces immediate attention rather than failing at runtime.

More inflexable type than never, and gives contextual error messages.

Type Parameters

  • S

Type declaration

  • [___error]: S

Example

function unsupported(): TypeErr<'Unsupported operation'> {
  throw new Error('Unsupported operation');
}

// Doesn't compile with error:
// Type TypeErr<'Unsupported operation'> is not assignable to type string
const result: string = unsupported();