Hyperlinkv0.8.0-beta.28

Types

Types.Invarianttypeeffect/Types.ts:578
(_: A): A

Function-type alias encoding invariant variance for a phantom type parameter.

When to use

Use as a phantom field type to make a type parameter invariant, neither covariant nor contravariant.

Details

A value of type Invariant<A> cannot be assigned to Invariant<B> unless A and B are the same type.

Example (Defining an invariant phantom type)

import type { Types } from "effect"

interface Container<T> {
  readonly _phantom: Types.Invariant<T>
  readonly value: T
}
modelsInvariant.TypeCovariantContravariant
Source effect/Types.ts:57835 lines
export type Invariant<A> = (_: A) => A

/**
 * Namespace for {@link Invariant}-related utilities.
 *
 * **When to use**
 *
 * Use when referring to type-level helpers nested under `Invariant`.
 *
 * @since 3.9.0
 */
export declare namespace Invariant {
  /**
   * Extracts the type parameter `A` from an `Invariant<A>`.
   *
   * **When to use**
   *
   * Use to recover the carried type from an invariant phantom marker.
   *
   * **Example** (Extracting the inner type)
   *
   * ```ts
   * import type { Types } from "effect"
   *
   * type Inner = Types.Invariant.Type<Types.Invariant<number>>
   * // number
   * ```
   *
   * @see {@link Invariant}
   *
   * @category models
   * @since 3.9.0
   */
  export type Type<A> = A extends Invariant<infer U> ? U : never
}
Referenced by 10 symbols