Types overview
A collection of types that are commonly used types.
Added in v2.0.0
Table of contents
models
Concurrency (type alias)
Describes the concurrency to use when executing multiple Effect’s.
Signature
export type Concurrency = number | "unbounded" | "inherit"
Added in v2.0.0
Contravariant (type alias)
Contravariant helper.
Signature
export type Contravariant<A> = (_: A) => void
Added in v2.0.0
Covariant (type alias)
Covariant helper.
Signature
export type Covariant<A> = (_: never) => A
Added in v2.0.0
Equals (type alias)
Determines if two types are equal.
Signature
export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
Example
import * as Types from "effect/Types"
type Res1 = Types.Equals<{ a: number }, { a: number }> // true
type Res2 = Types.Equals<{ a: number }, { b: number }> // false
Added in v2.0.0
Has (type alias)
Determines if a record contains any of the given keys.
Signature
export type Has<A, Key extends string> = (
Key extends infer K ? (K extends keyof A ? true : never) : never
) extends never
? false
: true
Example
import * as Types from "effect/Types"
type Res1 = Types.Has<{ a: number }, "a" | "b"> // true
type Res2 = Types.Has<{ c: number }, "a" | "b"> // false
Added in v2.0.0
Invariant (type alias)
Invariant helper.
Signature
export type Invariant<A> = (_: A) => A
Added in v2.0.0
MergeLeft (type alias)
Merges two object where the keys of the left object take precedence in the case of a conflict.
Signature
export type MergeLeft<K, H> = Simplify<{
[k in keyof K | keyof H]: k extends keyof K ? K[k] : k extends keyof H ? H[k] : never
}>
Example
import * as Types from "effect/Types"
type MergeLeft = Types.MergeLeft<{ a: number; b: number }, { a: string }> // { a: number; b: number; }
Added in v2.0.0
MergeRecord (type alias)
Signature
export type MergeRecord<K, H> = {
[k in keyof K | keyof H]: k extends keyof K ? K[k] : k extends keyof H ? H[k] : never
} extends infer X
? X
: never
Added in v2.0.0
MergeRight (type alias)
Merges two object where the keys of the right object take precedence in the case of a conflict.
Signature
export type MergeRight<K, H> = Simplify<{
[k in keyof K | keyof H]: k extends keyof H ? H[k] : k extends keyof K ? K[k] : never
}>
Example
import * as Types from "effect/Types"
type MergeRight = Types.MergeRight<{ a: number; b: number }, { a: string }> // { a: string; b: number; }
Added in v2.0.0
NoInfer (type alias)
Avoid inference on a specific parameter
Signature
export type NoInfer<A> = [A][A extends any ? 0 : never]
Added in v2.0.0
types
ExcludeTag (type alias)
Excludes the tagged object from the type.
Signature
export type ExcludeTag<E, K extends Tags<E>> = Exclude<E, { _tag: K }>
Example
import * as Types from "effect/Types"
type Res = Types.ExcludeTag<string | { _tag: "a" } | { _tag: "b" }, "a"> // string | { _tag: "b" }
Added in v2.0.0
ExtractTag (type alias)
Extracts the type of the given tag.
Signature
export type ExtractTag<E, K extends Tags<E>> = Extract<E, { _tag: K }>
Example
import * as Types from "effect/Types"
type Res = Types.ExtractTag<{ _tag: "a"; a: number } | { _tag: "b"; b: number }, "b"> // { _tag: "b", b: number }
Added in v2.0.0
Mutable (type alias)
Make all properties in T
mutable. Supports arrays, tuples, and records as well.
Signature
export type Mutable<T> = {
-readonly [P in keyof T]: T[P]
}
Example
import type * as Types from "effect/Types"
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; }
Added in v2.0.0
Simplify (type alias)
Simplifies the type signature of a type.
Signature
export type Simplify<A> = {
[K in keyof A]: A[K]
} extends infer B
? B
: never
Example
import * as Types from "effect/Types"
type Res = Types.Simplify<{ a: number } & { b: number }> // { a: number; b: number; }
Added in v2.0.0
Tags (type alias)
Returns the tags in a type.
Signature
export type Tags<E> = E extends { _tag: string } ? E["_tag"] : never
Example
import * as Types from "effect/Types"
type Res = Types.Tags<string | { _tag: "a" } | { _tag: "b" }> // "a" | "b"
Added in v2.0.0
UnionToIntersection (type alias)
A utility type that transforms a union type T
into an intersection type.
Signature
export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never
Added in v2.0.0
utils
MatchRecord (type alias)
Signature
export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse
Added in v2.0.0
NotFunction (type alias)
Signature
export type NotFunction<T> = T extends Function ? never : T
Added in v2.0.0