Skip to main content Link Search Menu Expand Document (external link)

Types.ts overview

A collection of types that are commonly used types.

Since v2.0.0


Exports Grouped by Category


models

Concurrency (type alias)

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

Signature

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

Source

Since v2.0.0

Contravariant (type alias)

Contravariant helper.

Signature

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

Source

Since v2.0.0

Contravariant (namespace)

Source

Since v3.9.0

Type (type alias)

Signature

type Type<A> = A extends Contravariant<infer U> ? U : never

Source

Since v3.9.0

Covariant (type alias)

Covariant helper.

Signature

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

Source

Since v2.0.0

Covariant (namespace)

Source

Since v3.9.0

Type (type alias)

Signature

type Type<A> = A extends Covariant<infer U> ? U : never

Source

Since v3.9.0

Equals (type alias)

Determines if two types are equal.

Example

import type { Types } from "effect"

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

Signature

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

Source

Since v2.0.0

Has (type alias)

Determines if a record contains any of the given keys.

Example

import type { Types } from "effect"

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

Signature

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

Source

Since v2.0.0

Invariant (type alias)

Invariant helper.

Signature

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

Source

Since v2.0.0

Invariant (namespace)

Source

Since v3.9.0

Type (type alias)

Signature

type Type<A> = A extends Invariant<infer U> ? U : never

Source

Since v3.9.0

MergeLeft (type alias)

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

Example

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

Signature

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

Source

Since v2.0.0

MergeRecord (type alias)

Signature

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

Source

Since v2.0.0

MergeRight (type alias)

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

Example

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

Signature

type MergeRight<Target, Source> = Simplify<
  Source & {
    [Key in keyof Target as Key extends keyof Source ? never : Key]: Target[Key]
  }
>

Source

Since v2.0.0

NoInfer (type alias)

Avoid inference on a specific parameter

Signature

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

Source

Since v2.0.0

tuples

TupleOf (type alias)

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.

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

Signature

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

Source

Since v3.3.0

TupleOfAtLeast (type alias)

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.

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

Signature

type [...TupleOf<N, T>, ...T[]] = [...TupleOf<N, T>, ...Array<T>]

Source

Since v3.3.0

types

DeepMutable (type alias)

Like Types.Mutable, but works recursively.

Example

import type { Types } from "effect"

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

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
        ? T
        : { -readonly [K in keyof T]: DeepMutable<T[K]> }

Source

Since v3.1.0

ExcludeTag (type alias)

Excludes the tagged object from the type.

Example

import type { Types } from "effect"

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

Signature

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

Source

Since v2.0.0

ExtractTag (type alias)

Extracts the type of the given tag.

Example

import type { Types } from "effect"

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

Signature

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

Source

Since v2.0.0

Mutable (type alias)

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

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; }

Signature

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

Source

Since v2.0.0

Simplify (type alias)

Simplifies the type signature of a type.

Example

import type { Types } from "effect"

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

Signature

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

Source

Since v2.0.0

Tags (type alias)

Returns the tags in a type.

Example

import type { Types } from "effect"

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

Signature

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

Source

Since v2.0.0

UnionToIntersection (type alias)

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

Source

Since v2.0.0

utils

MatchRecord (type alias)

Signature

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

Source

Since v2.0.0

NoExcessProperties (type alias)

Signature

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

Source

Since v3.9.0

NotFunction (type alias)

Signature

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

Source

Since v2.0.0