Skip to content

Types

A collection of types that are commonly used types.

28 exports Added in v2.0.0 Source

Models

Concurrency type

Added in v2.0.0 Source

Describes the concurrency to use when executing multiple Effect's.

Signature

type Concurrency = number | "unbounded" | "inherit";

Contravariant type

Added in v2.0.0 Source

Contravariant helper.

Signature

type Contravariant<A> = (_: A) => void;

Covariant

Added in v3.9.0 Source

Covariant type

Added in v2.0.0 Source

Covariant helper.

Signature

type Covariant<A> = (_: never) => A;

Equals type

Added in v2.0.0 Source

Determines if two types are equal.

Signature

type Equals<X, Y> = <T>() => T extends X
  ? 1
  : 2 extends <T>() => T extends Y ? 1 : 2
    ? true
    : false;

Example

import type { Types } from "effect"

type Res1 = Types.Equals<{ a: number }, { a: number }> // true
type Res2 = Types.Equals<{ a: number }, { b: number }> // false

EqualsWith type

Added in v3.15.0 Source

Determines if two types are equal, allowing to specify the return types.

Signature

type EqualsWith<A, B, Y, N> = <T>() => T extends A
  ? 1
  : 2 extends <T>() => T extends B ? 1 : 2
    ? Y
    : N;

Has type

Added in v2.0.0 Source

Determines if a record contains any of the given keys.

Signature

type Has<A, Key extends string> = Key extends infer K
  ? K extends keyof A
    ? true
    : never
  : never extends never
    ? false
    : true;

Example

import type { Types } from "effect"

type Res1 = Types.Has<{ a: number }, "a" | "b"> // true
type Res2 = Types.Has<{ c: number }, "a" | "b"> // false

Invariant

Added in v3.9.0 Source

Invariant type

Added in v2.0.0 Source

Invariant helper.

Signature

type Invariant<A> = (_: A) => A;

MergeLeft type

Added in v2.0.0 Source

Merges two object where the keys of the left object take precedence in the case of a conflict.

Signature

type MergeLeft<Source, Target> = MergeRight<Target, Source>;

Example

import type { Types } from "effect"
type MergeLeft = Types.MergeLeft<{ a: number; b: number }, { a: string }> // { a: number; b: number; }

MergeRecord type

Added in v2.0.0 Source

Signature

type MergeRecord<Source, Target> = MergeLeft<Source, Target>;

MergeRight type

Added in v2.0.0 Source

Merges two object where the keys of the right object take precedence in the case of a conflict.

Signature

type MergeRight<Target, Source> = Simplify<Source & { [Key in keyof Target]: Target[Key] }>;

Example

import type { Types } from "effect"
type MergeRight = Types.MergeRight<{ a: number; b: number }, { a: string }> // { a: string; b: number; }

NoInfer type

Added in v2.0.0 Source

Avoid inference on a specific parameter

Signature

type NoInfer<A> = [A][A extends any ? 0 : never];

Other

Ctor type

Added in v3.15.0 Source

Signature

type Ctor<T = {}> = (...args: Array<any>) => T;

MatchRecord type

Added in v2.0.0 Source

Signature

type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse;

NoExcessProperties type

Added in v3.9.0 Source

Signature

type NoExcessProperties<T, U> = T & { [K in Exclude<keyof U, keyof T>]: never };

NotFunction type

Added in v2.0.0 Source

Signature

type NotFunction<T> = T extends Function ? never : T;

VoidIfEmpty type

Added in v3.19.20 Source

Conditional type that returns void if S is an empty object type, otherwise returns S.

Signature

type VoidIfEmpty<S> = keyof S extends never ? void : S;

Tuples

TupleOf type

Added in v3.3.0 Source

Represents a tuple with a fixed number of elements of type T.

This type constructs a tuple that has exactly N elements of type T.

Signature

type TupleOf<N extends number, T> = N extends N
  ? number extends N
    ? Array<T>
    : _TupleOf<T, N, []>
  : never;

Example

import { TupleOf } from "effect/Types"

// A tuple with exactly 3 numbers
const example1: TupleOf<3, number> = [1, 2, 3] // valid
// @ts-expect-error
const example2: TupleOf<3, number> = [1, 2] // invalid
// @ts-expect-error
const example3: TupleOf<3, number> = [1, 2, 3, 4] // invalid

TupleOfAtLeast type

Added in v3.3.0 Source

Represents a tuple with at least N elements of type T.

This type constructs a tuple that has a fixed number of elements N of type T at the start, followed by any number (including zero) of additional elements of the same type T.

Signature

type TupleOfAtLeast<N extends number, T> = [...TupleOf<N, T>, ...Array<T>];

Example

import { TupleOfAtLeast } from "effect/Types"

// A tuple with at least 3 numbers
const example1: TupleOfAtLeast<3, number> = [1, 2, 3] // valid
const example2: TupleOfAtLeast<3, number> = [1, 2, 3, 4, 5] // valid
// @ts-expect-error
const example3: TupleOfAtLeast<3, number> = [1, 2] // invalid

Types

DeepMutable type

Added in v3.1.0 Source

Like Types.Mutable, but works recursively.

Signature

type DeepMutable<T> =
  T extends ReadonlyMap<infer K, infer V>
    ? Map<DeepMutable<K>, DeepMutable<V>>
    : T extends ReadonlySet<infer V>
      ? Set<DeepMutable<V>>
      : T extends string | number | boolean | bigint | symbol | Function
        ? T
        : { [K in keyof T]: DeepMutable<T[K]> };

Example

import type { Types } from "effect"

type DeepMutableStruct = Types.DeepMutable<{
  readonly a: string
  readonly b: readonly string[]
}>
// { a: string; b: string[] }

ExcludeTag type

Added in v2.0.0 Source

Excludes the tagged object from the type.

Signature

type ExcludeTag<E, K extends Tags<E>> = Exclude<
  E,
  {
    _tag: K;
  }
>;

Example

import type { Types } from "effect"

type Res = Types.ExcludeTag<string | { _tag: "a" } | { _tag: "b" }, "a"> // string | { _tag: "b" }

ExtractTag type

Added in v2.0.0 Source

Extracts the type of the given tag.

Signature

type ExtractTag<E, K extends Tags<E>> = Extract<
  E,
  {
    _tag: K;
  }
>;

Example

import type { Types } from "effect"

type Res = Types.ExtractTag<{ _tag: "a"; a: number } | { _tag: "b"; b: number }, "b"> // { _tag: "b", b: number }

Mutable type

Added in v2.0.0 Source

Make all properties in T mutable. Supports arrays, tuples, and records as well.

Signature

type Mutable<T> = { [P in keyof T]: T[P] };

Example

import type { Types } from "effect"

type MutableStruct = Types.Mutable<{ readonly a: string; readonly b: number }> // { a: string; b: number; }

type MutableArray = Types.Mutable<ReadonlyArray<string>> // string[]

type MutableTuple = Types.Mutable<readonly [string, number]> // [string, number]

type MutableRecord = Types.Mutable<{ readonly [_: string]: number }> // { [x: string]: number; }

Simplify type

Added in v2.0.0 Source

Simplifies the type signature of a type.

Signature

type Simplify<A> = { [K in keyof A]: A[K] } extends infer B ? B : never;

Example

import type { Types } from "effect"

type Res = Types.Simplify<{ a: number } & { b: number }> // { a: number; b: number; }

Tags type

Added in v2.0.0 Source

Returns the tags in a type.

Signature

type Tags<E> = E extends {
  _tag: string;
}
  ? E["_tag"]
  : never;

Example

import type { Types } from "effect"

type Res = Types.Tags<string | { _tag: "a" } | { _tag: "b" }> // "a" | "b"

UnionToIntersection type

Added in v2.0.0 Source

A utility type that transforms a union type T into an intersection type.

Signature

type UnionToIntersection<T> = T extends any
  ? (x: T) => any
  : never extends (x: infer R) => any
    ? R
    : never;