Hyperlinkv0.8.0-beta.28

Types

Types.Covarianttypeeffect/Types.ts:646
(_: never): A

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

When to use

Use as a phantom field type to make a type parameter covariant in output position.

Details

Covariant<A> is assignable to Covariant<B> when A extends B, following the subtype direction.

Example (Defining a covariant phantom type)

import type { Types } from "effect"

interface Producer<T> {
  readonly _phantom: Types.Covariant<T>
  readonly get: () => T
}
modelsCovariant.TypeContravariantInvariant
Source effect/Types.ts:64635 lines
export type Covariant<A> = (_: never) => A

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