Hyperlinkv0.8.0-beta.28

Types

Types.Contravarianttypeeffect/Types.ts:714
(_: A): void

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

When to use

Use as a phantom field type to make a type parameter contravariant in input position.

Details

Contravariant<A> is assignable to Contravariant<B> when B extends A, following the supertype direction.

Example (Defining a contravariant phantom type)

import type { Types } from "effect"

interface Consumer<T> {
  readonly _phantom: Types.Contravariant<T>
  readonly accept: (value: T) => void
}
modelsContravariant.TypeCovariantInvariant
Source effect/Types.ts:71435 lines
export type Contravariant<A> = (_: A) => void

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