anyA namespace containing utility types for Match operations.
Details
This namespace provides advanced type-level utilities used internally by the Match module to perform complex pattern matching, type narrowing, and filter application. These types enable the sophisticated type inference that makes pattern matching both type-safe and ergonomic.
export declare namespace Types {
/**
* Computes the matched type when a pattern P is applied to type R.
*
* **Details**
*
* This utility type determines what type a value will have after successfully
* matching against a pattern. It handles refinements, predicates, and complex
* object patterns to provide accurate type narrowing.
*
* **Example** (Computing matched types)
*
* ```ts
* import type { Match } from "effect"
*
* // WhenMatch computes the narrowed type after pattern matching
* type StringMatch = Match.Types.WhenMatch<string | number, typeof Match.string>
* // Result: string
*
* type ObjectMatch = Match.Types.WhenMatch<
* { type: "user"; name: string } | {
* type: "admin"
* permissions: Array<string>
* },
* { type: "user" }
* >
* // Result: { type: "user"; name: string }
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.WhenMatch<R, P> = [0] extends [1 & R] ? ResolvePred<P, any> : P extends SafeRefinement<infer SP, never> ? SP : P extends Predicate.Refinement<infer _R, infer RP extends infer _R> ? [Extract<R, RP>] extends [infer X] ? [X] extends [never] ? RP : X : never : P extends PredicateA<infer PP> ? PP : ExtractMatch<R, P>Computes the matched type when a pattern P is applied to type R.
Details
This utility type determines what type a value will have after successfully
matching against a pattern. It handles refinements, predicates, and complex
object patterns to provide accurate type narrowing.
Example (Computing matched types)
import type { Match } from "effect"
// WhenMatch computes the narrowed type after pattern matching
type StringMatch = Match.Types.WhenMatch<string | number, typeof Match.string>
// Result: string
type ObjectMatch = Match.Types.WhenMatch<
{ type: "user"; name: string } | {
type: "admin"
permissions: Array<string>
},
{ type: "user" }
>
// Result: { type: "user"; name: string }
WhenMatch<function (type parameter) R in type Types.WhenMatch<R, P>R, function (type parameter) P in type Types.WhenMatch<R, P>P> =
// check for any
[0] extends [1 & function (type parameter) R in type Types.WhenMatch<R, P>R] ? type Types.ResolvePred<A, Input = any> = A extends never ? never : A extends SafeRefinement<infer _A, infer _R> ? _A : A extends Predicate.Refinement<Input, infer P extends Input> ? P : A extends Predicate.Predicate<infer P> ? P : A extends Record<string, any> ? { [K in keyof A]: ResolvePred<A[K], any>; } : AResolvePred<function (type parameter) P in type Types.WhenMatch<R, P>P> :
function (type parameter) P in type Types.WhenMatch<R, P>P extends interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<infer function (type parameter) SPSP, never> ? function (type parameter) SPSP
: function (type parameter) P in type Types.WhenMatch<R, P>P extends import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<infer function (type parameter) _R_R, infer function (type parameter) RPRP>
// try to narrow refinement
? [type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) R in type Types.WhenMatch<R, P>R, function (type parameter) RPRP>] extends [infer function (type parameter) XX] ? [function (type parameter) XX] extends [never]
// fallback to original refinement
? function (type parameter) RPRP
: function (type parameter) XX
: never
: function (type parameter) P in type Types.WhenMatch<R, P>P extends type Types.PredicateA<A> = Predicate.Predicate<A> | Predicate.Refinement<A, A>PredicateA<infer function (type parameter) PPPP> ? function (type parameter) PPPP
: type Types.ExtractMatch<I, P> = [ExtractAndNarrow<I, P>] extends [infer EI] ? EI : neverExtracts and narrows the matched type from an input type given a pattern.
Details
This is the core type utility that performs the actual type extraction
and narrowing logic. It handles the complex type-level computation that
determines what type results from applying a pattern to an input type.
Example (Extracting matched types)
import { Match } from "effect"
type StringExtract = Match.Types.ExtractMatch<
string | number | boolean,
typeof Match.string
>
// Result: string
type ObjectExtract = Match.Types.ExtractMatch<
{ type: "user"; name: string } | { type: "admin"; role: string },
{ type: "user" }
>
// Result: { type: "user"; name: string }
// This powers the type narrowing in:
Match.when(Match.string, (s) => s.toUpperCase())
// ^^^ s is correctly typed as string
ExtractMatch<function (type parameter) R in type Types.WhenMatch<R, P>R, function (type parameter) P in type Types.WhenMatch<R, P>P>
/**
* Computes the remaining type when a pattern P is excluded from type R.
*
* **Details**
*
* This utility type determines what type remains after a `Match.not` pattern
* excludes certain values. It's the complement of `WhenMatch`, calculating
* what's left after removing the matched portion.
*
* **Example** (Computing unmatched types)
*
* ```ts
* import type { Match } from "effect"
*
* // NotMatch computes what remains after exclusion
* type NotString = Match.Types.NotMatch<
* string | number | boolean,
* typeof Match.string
* >
* // Result: number | boolean
*
* type NotSpecificValue = Match.Types.NotMatch<"a" | "b" | "c", "a">
* // Result: "b" | "c"
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.NotMatch<R, P> = R extends ExtractMatch<R, PForNotMatch<P>> ? never : RComputes the remaining type when a pattern P is excluded from type R.
Details
This utility type determines what type remains after a Match.not pattern
excludes certain values. It's the complement of WhenMatch, calculating
what's left after removing the matched portion.
Example (Computing unmatched types)
import type { Match } from "effect"
// NotMatch computes what remains after exclusion
type NotString = Match.Types.NotMatch<
string | number | boolean,
typeof Match.string
>
// Result: number | boolean
type NotSpecificValue = Match.Types.NotMatch<"a" | "b" | "c", "a">
// Result: "b" | "c"
NotMatch<function (type parameter) R in type Types.NotMatch<R, P>R, function (type parameter) P in type Types.NotMatch<R, P>P> = type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in type Types.NotMatch<R, P>R, type Types.ExtractMatch<I, P> = [ExtractAndNarrow<I, P>] extends [infer EI] ? EI : neverExtracts and narrows the matched type from an input type given a pattern.
Details
This is the core type utility that performs the actual type extraction
and narrowing logic. It handles the complex type-level computation that
determines what type results from applying a pattern to an input type.
Example (Extracting matched types)
import { Match } from "effect"
type StringExtract = Match.Types.ExtractMatch<
string | number | boolean,
typeof Match.string
>
// Result: string
type ObjectExtract = Match.Types.ExtractMatch<
{ type: "user"; name: string } | { type: "admin"; role: string },
{ type: "user" }
>
// Result: { type: "user"; name: string }
// This powers the type narrowing in:
Match.when(Match.string, (s) => s.toUpperCase())
// ^^^ s is correctly typed as string
ExtractMatch<function (type parameter) R in type Types.NotMatch<R, P>R, type Types.PForNotMatch<P> = [ToInvertedRefinement<P>] extends [infer X] ? X : neverPForNotMatch<function (type parameter) P in type Types.NotMatch<R, P>P>>>
type type Types.PForNotMatch<P> = [ToInvertedRefinement<P>] extends [infer X] ? X : neverPForNotMatch<function (type parameter) P in type Types.PForNotMatch<P>P> = [type Types.ToInvertedRefinement<A> = A extends never ? never : A extends Predicate.Refinement<any, infer P extends any> ? SafeRefinement<P, P> : A extends Predicate.Predicate<infer _P> ? SafeRefinement<never, never> : A extends SafeRefinement<infer _A, infer _R> ? SafeRefinement<_R, _R> : A extends Record<string, any> ? { [K in keyof A]: ToInvertedRefinement<A[K]>; } : NonLiteralsTo<A, never>ToInvertedRefinement<function (type parameter) P in type Types.PForNotMatch<P>P>] extends [infer function (type parameter) XX] ? function (type parameter) XX
: never
/**
* Resolves a pattern to its matched type for use in type computations.
*
* **Details**
*
* This utility type processes patterns (predicates, refinements, objects)
* and resolves them to their corresponding matched types. It's used internally
* to compute type transformations during pattern matching.
*
* **Example** (Resolving match patterns)
*
* ```ts
* import type { Match } from "effect"
*
* // PForMatch resolves patterns to their matched types
* type StringPattern = Match.Types.PForMatch<typeof Match.string>
* // Result: string
*
* type ObjectPattern = Match.Types.PForMatch<{ name: string }>
* // Result: { name: string }
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.PForMatch<P> = [ResolvePred<P, any>] extends [infer X] ? X : neverResolves a pattern to its matched type for use in type computations.
Details
This utility type processes patterns (predicates, refinements, objects)
and resolves them to their corresponding matched types. It's used internally
to compute type transformations during pattern matching.
Example (Resolving match patterns)
import type { Match } from "effect"
// PForMatch resolves patterns to their matched types
type StringPattern = Match.Types.PForMatch<typeof Match.string>
// Result: string
type ObjectPattern = Match.Types.PForMatch<{ name: string }>
// Result: { name: string }
PForMatch<function (type parameter) P in type Types.PForMatch<P>P> = [type Types.ResolvePred<A, Input = any> = A extends never ? never : A extends SafeRefinement<infer _A, infer _R> ? _A : A extends Predicate.Refinement<Input, infer P extends Input> ? P : A extends Predicate.Predicate<infer P> ? P : A extends Record<string, any> ? { [K in keyof A]: ResolvePred<A[K], any>; } : AResolvePred<function (type parameter) P in type Types.PForMatch<P>P>] extends [infer function (type parameter) XX] ? function (type parameter) XX
: never
/**
* Computes the excluded type when a pattern P is used for exclusion.
*
* **Details**
*
* This utility type determines what should be excluded from a union type
* when a pattern is used in filtering operations. It transforms patterns
* into their exclusion-safe representations.
*
* **Example** (Computing excluded patterns)
*
* ```ts
* import type { Match } from "effect"
*
* // PForExclude computes what to exclude from type operations
* type ExcludeString = Match.Types.PForExclude<typeof Match.string>
* // Used internally to filter out string types
*
* type ExcludeObject = Match.Types.PForExclude<{ type: "admin" }>
* // Used internally to filter out admin objects
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.PForExclude<P> = [SafeRefinementR<ToSafeRefinement<P>>] extends [infer X] ? X : neverComputes the excluded type when a pattern P is used for exclusion.
Details
This utility type determines what should be excluded from a union type
when a pattern is used in filtering operations. It transforms patterns
into their exclusion-safe representations.
Example (Computing excluded patterns)
import type { Match } from "effect"
// PForExclude computes what to exclude from type operations
type ExcludeString = Match.Types.PForExclude<typeof Match.string>
// Used internally to filter out string types
type ExcludeObject = Match.Types.PForExclude<{ type: "admin" }>
// Used internally to filter out admin objects
PForExclude<function (type parameter) P in type Types.PForExclude<P>P> = [type Types.SafeRefinementR<A> = A extends never ? never : A extends SafeRefinement<infer _, infer R> ? R : A extends Function ? A : A extends Record<string, any> ? { [K in keyof A]: SafeRefinementR<A[K]>; } : ASafeRefinementR<type Types.ToSafeRefinement<A> = A extends never ? never : A extends Predicate.Refinement<any, infer P extends any> ? SafeRefinement<P, P> : A extends Predicate.Predicate<infer P> ? SafeRefinement<P, never> : A extends SafeRefinement<any, any> ? A : A extends Record<string, any> ? { [K in keyof A]: ToSafeRefinement<A[K]>; } : NonLiteralsTo<A, never>ToSafeRefinement<function (type parameter) P in type Types.PForExclude<P>P>>] extends [infer function (type parameter) XX] ? function (type parameter) XX
: never
// utilities
type type Types.PredicateA<A> = Predicate.Predicate<A> | Predicate.Refinement<A, A>PredicateA<function (type parameter) A in type Types.PredicateA<A>A> = import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in type Types.PredicateA<A>A> | import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) A in type Types.PredicateA<A>A, function (type parameter) A in type Types.PredicateA<A>A>
type type Types.SafeRefinementR<A> = A extends never ? never : A extends SafeRefinement<infer _, infer R> ? R : A extends Function ? A : A extends Record<string, any> ? { [K in keyof A]: SafeRefinementR<A[K]>; } : ASafeRefinementR<function (type parameter) A in type Types.SafeRefinementR<A>A> = function (type parameter) A in type Types.SafeRefinementR<A>A extends never ? never
: function (type parameter) A in type Types.SafeRefinementR<A>A extends interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<infer function (type parameter) __, infer function (type parameter) RR> ? function (type parameter) RR
: function (type parameter) A in type Types.SafeRefinementR<A>A extends Function ? function (type parameter) A in type Types.SafeRefinementR<A>A
: function (type parameter) A in type Types.SafeRefinementR<A>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> ? { [function (type parameter) KK in keyof function (type parameter) A in type Types.SafeRefinementR<A>A]: type Types.SafeRefinementR<A> = A extends never ? never : A extends SafeRefinement<infer _, infer R> ? R : A extends Function ? A : A extends Record<string, any> ? { [K in keyof A]: SafeRefinementR<A[K]>; } : ASafeRefinementR<function (type parameter) A in type Types.SafeRefinementR<A>A[function (type parameter) KK]> }
: function (type parameter) A in type Types.SafeRefinementR<A>A
type type Types.ResolvePred<A, Input = any> = A extends never ? never : A extends SafeRefinement<infer _A, infer _R> ? _A : A extends Predicate.Refinement<Input, infer P extends Input> ? P : A extends Predicate.Predicate<infer P> ? P : A extends Record<string, any> ? { [K in keyof A]: ResolvePred<A[K], any>; } : AResolvePred<function (type parameter) A in type Types.ResolvePred<A, Input = any>A, function (type parameter) Input in type Types.ResolvePred<A, Input = any>Input = any> = function (type parameter) A in type Types.ResolvePred<A, Input = any>A extends never ? never
: function (type parameter) A in type Types.ResolvePred<A, Input = any>A extends interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<infer function (type parameter) _A_A, infer function (type parameter) _R_R> ? function (type parameter) _A_A
: function (type parameter) A in type Types.ResolvePred<A, Input = any>A extends import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) Input in type Types.ResolvePred<A, Input = any>Input, infer function (type parameter) PP> ? function (type parameter) PP
: function (type parameter) A in type Types.ResolvePred<A, Input = any>A extends import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<infer function (type parameter) PP> ? function (type parameter) PP
: function (type parameter) A in type Types.ResolvePred<A, Input = any>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> ? { [function (type parameter) KK in keyof function (type parameter) A in type Types.ResolvePred<A, Input = any>A]: type Types.ResolvePred<A, Input = any> = A extends never ? never : A extends SafeRefinement<infer _A, infer _R> ? _A : A extends Predicate.Refinement<Input, infer P extends Input> ? P : A extends Predicate.Predicate<infer P> ? P : A extends Record<string, any> ? { [K in keyof A]: ResolvePred<A[K], any>; } : AResolvePred<function (type parameter) A in type Types.ResolvePred<A, Input = any>A[function (type parameter) KK]> }
: function (type parameter) A in type Types.ResolvePred<A, Input = any>A
type type Types.ToSafeRefinement<A> = A extends never ? never : A extends Predicate.Refinement<any, infer P extends any> ? SafeRefinement<P, P> : A extends Predicate.Predicate<infer P> ? SafeRefinement<P, never> : A extends SafeRefinement<any, any> ? A : A extends Record<string, any> ? { [K in keyof A]: ToSafeRefinement<A[K]>; } : NonLiteralsTo<A, never>ToSafeRefinement<function (type parameter) A in type Types.ToSafeRefinement<A>A> = function (type parameter) A in type Types.ToSafeRefinement<A>A extends never ? never
: function (type parameter) A in type Types.ToSafeRefinement<A>A extends import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<any, infer function (type parameter) PP> ? interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<function (type parameter) PP, function (type parameter) PP>
: function (type parameter) A in type Types.ToSafeRefinement<A>A extends import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<infer function (type parameter) PP> ? interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<function (type parameter) PP, never>
: function (type parameter) A in type Types.ToSafeRefinement<A>A extends interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<any> ? function (type parameter) A in type Types.ToSafeRefinement<A>A
: function (type parameter) A in type Types.ToSafeRefinement<A>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> ? { [function (type parameter) KK in keyof function (type parameter) A in type Types.ToSafeRefinement<A>A]: type Types.ToSafeRefinement<A> = A extends never ? never : A extends Predicate.Refinement<any, infer P extends any> ? SafeRefinement<P, P> : A extends Predicate.Predicate<infer P> ? SafeRefinement<P, never> : A extends SafeRefinement<any, any> ? A : A extends Record<string, any> ? { [K in keyof A]: ToSafeRefinement<A[K]>; } : NonLiteralsTo<A, never>ToSafeRefinement<function (type parameter) A in type Types.ToSafeRefinement<A>A[function (type parameter) KK]> }
: type Types.NonLiteralsTo<A, T> = [A] extends [string | number | bigint | boolean] ? [string] extends [A] ? T : [number] extends [A] ? T : [boolean] extends [A] ? T : [bigint] extends [A] ? T : A : ANonLiteralsTo<function (type parameter) A in type Types.ToSafeRefinement<A>A, never>
type type Types.ToInvertedRefinement<A> = A extends never ? never : A extends Predicate.Refinement<any, infer P extends any> ? SafeRefinement<P, P> : A extends Predicate.Predicate<infer _P> ? SafeRefinement<never, never> : A extends SafeRefinement<infer _A, infer _R> ? SafeRefinement<_R, _R> : A extends Record<string, any> ? { [K in keyof A]: ToInvertedRefinement<A[K]>; } : NonLiteralsTo<A, never>ToInvertedRefinement<function (type parameter) A in type Types.ToInvertedRefinement<A>A> = function (type parameter) A in type Types.ToInvertedRefinement<A>A extends never ? never
: function (type parameter) A in type Types.ToInvertedRefinement<A>A extends import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<any, infer function (type parameter) PP> ? interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<function (type parameter) PP>
: function (type parameter) A in type Types.ToInvertedRefinement<A>A extends import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<infer function (type parameter) _P_P> ? interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<never>
: function (type parameter) A in type Types.ToInvertedRefinement<A>A extends interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<infer function (type parameter) _A_A, infer function (type parameter) _R_R> ? interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<function (type parameter) _R_R>
: function (type parameter) A in type Types.ToInvertedRefinement<A>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> ? { [function (type parameter) KK in keyof function (type parameter) A in type Types.ToInvertedRefinement<A>A]: type Types.ToInvertedRefinement<A> = A extends never ? never : A extends Predicate.Refinement<any, infer P extends any> ? SafeRefinement<P, P> : A extends Predicate.Predicate<infer _P> ? SafeRefinement<never, never> : A extends SafeRefinement<infer _A, infer _R> ? SafeRefinement<_R, _R> : A extends Record<string, any> ? { [K in keyof A]: ToInvertedRefinement<A[K]>; } : NonLiteralsTo<A, never>ToInvertedRefinement<function (type parameter) A in type Types.ToInvertedRefinement<A>A[function (type parameter) KK]> }
: type Types.NonLiteralsTo<A, T> = [A] extends [string | number | bigint | boolean] ? [string] extends [A] ? T : [number] extends [A] ? T : [boolean] extends [A] ? T : [bigint] extends [A] ? T : A : ANonLiteralsTo<function (type parameter) A in type Types.ToInvertedRefinement<A>A, never>
type type Types.NonLiteralsTo<A, T> = [A] extends [string | number | bigint | boolean] ? [string] extends [A] ? T : [number] extends [A] ? T : [boolean] extends [A] ? T : [bigint] extends [A] ? T : A : ANonLiteralsTo<function (type parameter) A in type Types.NonLiteralsTo<A, T>A, function (type parameter) T in type Types.NonLiteralsTo<A, T>T> = [function (type parameter) A in type Types.NonLiteralsTo<A, T>A] extends [string | number | boolean | bigint] ? [string] extends [function (type parameter) A in type Types.NonLiteralsTo<A, T>A] ? function (type parameter) T in type Types.NonLiteralsTo<A, T>T
: [number] extends [function (type parameter) A in type Types.NonLiteralsTo<A, T>A] ? function (type parameter) T in type Types.NonLiteralsTo<A, T>T
: [boolean] extends [function (type parameter) A in type Types.NonLiteralsTo<A, T>A] ? function (type parameter) T in type Types.NonLiteralsTo<A, T>T
: [bigint] extends [function (type parameter) A in type Types.NonLiteralsTo<A, T>A] ? function (type parameter) T in type Types.NonLiteralsTo<A, T>T
: function (type parameter) A in type Types.NonLiteralsTo<A, T>A
: function (type parameter) A in type Types.NonLiteralsTo<A, T>A
/**
* Defines the structure for complex object and array patterns.
*
* **Details**
*
* This type represents patterns that can match against complex data structures
* like objects and arrays. It supports nested pattern matching and partial
* object matching, enabling sophisticated pattern compositions.
*
* **Example** (Describing complex object patterns)
*
* ```ts
* import { Match } from "effect"
*
* // PatternBase enables complex object patterns
* type UserPattern = Match.Types.PatternBase<{
* name: string
* age: number
* role: "admin" | "user"
* }>
* // Allows: { name?: string | Predicate, age?: number | Predicate, ... }
*
* // Example usage:
* Match.value({ name: "Alice", age: 30, role: "admin" as const }).pipe(
* Match.when(
* { age: (n: number) => n >= 18, role: "admin" },
* (user: { name: string; age: number; role: "admin" }) =>
* `Admin: ${user.name}`
* ),
* Match.orElse(() => "Not an adult admin")
* )
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.PatternBase<A> = A extends readonly (infer _T)[] ? readonly any[] | PatternPrimitive<A> : A extends Record<string, any> ? Partial<{ [K in keyof A]: PatternPrimitive<A[K] & {}> | PatternBase<A[K] & {}>; }> : neverDefines the structure for complex object and array patterns.
Details
This type represents patterns that can match against complex data structures
like objects and arrays. It supports nested pattern matching and partial
object matching, enabling sophisticated pattern compositions.
Example (Describing complex object patterns)
import { Match } from "effect"
// PatternBase enables complex object patterns
type UserPattern = Match.Types.PatternBase<{
name: string
age: number
role: "admin" | "user"
}>
// Allows: { name?: string | Predicate, age?: number | Predicate, ... }
// Example usage:
Match.value({ name: "Alice", age: 30, role: "admin" as const }).pipe(
Match.when(
{ age: (n: number) => n >= 18, role: "admin" },
(user: { name: string; age: number; role: "admin" }) =>
`Admin: ${user.name}`
),
Match.orElse(() => "Not an adult admin")
)
PatternBase<function (type parameter) A in type Types.PatternBase<A>A> = function (type parameter) A in type Types.PatternBase<A>A extends interface ReadonlyArray<T>ReadonlyArray<infer function (type parameter) _T_T> ? interface ReadonlyArray<T>ReadonlyArray<any> | type Types.PatternPrimitive<A> = A | PredicateA<A> | SafeRefinement<any, any>Defines primitive patterns that can match simple values.
Details
This type represents the building blocks of pattern matching: predicates,
literal values, and safe refinements. These are the atomic patterns that
can be composed into more complex matching logic.
PatternPrimitive<function (type parameter) A in type Types.PatternBase<A>A>
: function (type parameter) A in type Types.PatternBase<A>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> ? type Partial<T> = {
[P in keyof T]?: T[P] | undefined
}
Make all properties in T optional
Partial<
{ [function (type parameter) KK in keyof function (type parameter) A in type Types.PatternBase<A>A]: type Types.PatternPrimitive<A> = A | PredicateA<A> | SafeRefinement<any, any>Defines primitive patterns that can match simple values.
Details
This type represents the building blocks of pattern matching: predicates,
literal values, and safe refinements. These are the atomic patterns that
can be composed into more complex matching logic.
PatternPrimitive<function (type parameter) A in type Types.PatternBase<A>A[function (type parameter) KK] & {}> | type Types.PatternBase<A> = A extends readonly (infer _T)[] ? readonly any[] | PatternPrimitive<A> : A extends Record<string, any> ? Partial<{ [K in keyof A]: PatternPrimitive<A[K] & {}> | PatternBase<A[K] & {}>; }> : neverDefines the structure for complex object and array patterns.
Details
This type represents patterns that can match against complex data structures
like objects and arrays. It supports nested pattern matching and partial
object matching, enabling sophisticated pattern compositions.
Example (Describing complex object patterns)
import { Match } from "effect"
// PatternBase enables complex object patterns
type UserPattern = Match.Types.PatternBase<{
name: string
age: number
role: "admin" | "user"
}>
// Allows: { name?: string | Predicate, age?: number | Predicate, ... }
// Example usage:
Match.value({ name: "Alice", age: 30, role: "admin" as const }).pipe(
Match.when(
{ age: (n: number) => n >= 18, role: "admin" },
(user: { name: string; age: number; role: "admin" }) =>
`Admin: ${user.name}`
),
Match.orElse(() => "Not an adult admin")
)
PatternBase<function (type parameter) A in type Types.PatternBase<A>A[function (type parameter) KK] & {}> }
>
: never
/**
* Defines primitive patterns that can match simple values.
*
* **Details**
*
* This type represents the building blocks of pattern matching: predicates,
* literal values, and safe refinements. These are the atomic patterns that
* can be composed into more complex matching logic.
*
* @category types
* @since 4.0.0
*/
export type type Types.PatternPrimitive<A> = A | PredicateA<A> | SafeRefinement<any, any>Defines primitive patterns that can match simple values.
Details
This type represents the building blocks of pattern matching: predicates,
literal values, and safe refinements. These are the atomic patterns that
can be composed into more complex matching logic.
PatternPrimitive<function (type parameter) A in type Types.PatternPrimitive<A>A> = type Types.PredicateA<A> = Predicate.Predicate<A> | Predicate.Refinement<A, A>PredicateA<function (type parameter) A in type Types.PatternPrimitive<A>A> | function (type parameter) A in type Types.PatternPrimitive<A>A | interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<any>
/**
* Represents a filter that excludes specific types from a union.
*
* **Details**
*
* `Without` is used internally to track which types should be excluded
* from consideration during pattern matching. It helps implement the
* type-level logic for `Match.not` and other exclusion operations.
*
* **Example** (Tracking excluded types)
*
* ```ts
* import { Match } from "effect"
*
* // Without is used internally when you write:
* Match.type<string | number | boolean>().pipe(
* Match.not(Match.string, (value) => `not string: ${value}`),
* // At this point, type system uses Without<string> to track exclusion
* Match.orElse(() => "was a string")
* )
* ```
*
* @category types
* @since 4.0.0
*/
export interface interface Types.Without<out X>Represents a filter that excludes specific types from a union.
Details
Without is used internally to track which types should be excluded
from consideration during pattern matching. It helps implement the
type-level logic for Match.not and other exclusion operations.
Example (Tracking excluded types)
import { Match } from "effect"
// Without is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.not(Match.string, (value) => `not string: ${value}`),
// At this point, type system uses Without<string> to track exclusion
Match.orElse(() => "was a string")
)
Without<out function (type parameter) X in Without<out X>X> {
readonly Types.Without<out X>._tag: "Without"_tag: "Without"
readonly Types.Without<out X>._X: out X_X: function (type parameter) X in Without<out X>X
}
/**
* Represents a filter that includes only specific types from a union.
*
* **Details**
*
* `Only` is used internally to track which types should be exclusively
* considered during pattern matching. It helps implement the type-level
* logic for positive matches and type narrowing.
*
* **Example** (Tracking included types)
*
* ```ts
* import { Match } from "effect"
*
* // Only is used internally when you write:
* Match.type<string | number | boolean>().pipe(
* Match.when(Match.string, (s) => `string: ${s}`),
* // At this point, type system uses Only<string> for the match
* Match.orElse((value) => `not string: ${value}`)
* )
* ```
*
* @category types
* @since 4.0.0
*/
export interface interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<out function (type parameter) X in Only<out X>X> {
readonly Types.Only<out X>._tag: "Only"_tag: "Only"
readonly Types.Only<out X>._X: out X_X: function (type parameter) X in Only<out X>X
}
/**
* Adds a type to the exclusion filter, expanding what should be filtered out.
*
* **Details**
*
* This utility type manages the accumulation of excluded types during
* pattern matching. When multiple exclusions are applied, it combines
* them into a single filter representation.
*
* **Example** (Accumulating excluded types)
*
* ```ts
* import { Match } from "effect"
*
* // AddWithout is used when combining multiple exclusions:
* Match.type<string | number | boolean | null>().pipe(
* Match.not(Match.string, () => "not string"),
* Match.not(Match.number, () => "not number"),
* // Type system uses AddWithout to combine exclusions
* Match.orElse(() => "was string or number")
* )
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.AddWithout<A, X> = [A] extends [Without<infer WX>] ? Without<X | WX> : [A] extends [Only<infer OX>] ? Only<Exclude<OX, X>> : neverAdds a type to the exclusion filter, expanding what should be filtered out.
Details
This utility type manages the accumulation of excluded types during
pattern matching. When multiple exclusions are applied, it combines
them into a single filter representation.
Example (Accumulating excluded types)
import { Match } from "effect"
// AddWithout is used when combining multiple exclusions:
Match.type<string | number | boolean | null>().pipe(
Match.not(Match.string, () => "not string"),
Match.not(Match.number, () => "not number"),
// Type system uses AddWithout to combine exclusions
Match.orElse(() => "was string or number")
)
AddWithout<function (type parameter) A in type Types.AddWithout<A, X>A, function (type parameter) X in type Types.AddWithout<A, X>X> = [function (type parameter) A in type Types.AddWithout<A, X>A] extends [interface Types.Without<out X>Represents a filter that excludes specific types from a union.
Details
Without is used internally to track which types should be excluded
from consideration during pattern matching. It helps implement the
type-level logic for Match.not and other exclusion operations.
Example (Tracking excluded types)
import { Match } from "effect"
// Without is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.not(Match.string, (value) => `not string: ${value}`),
// At this point, type system uses Without<string> to track exclusion
Match.orElse(() => "was a string")
)
Without<infer function (type parameter) WXWX>] ? interface Types.Without<out X>Represents a filter that excludes specific types from a union.
Details
Without is used internally to track which types should be excluded
from consideration during pattern matching. It helps implement the
type-level logic for Match.not and other exclusion operations.
Example (Tracking excluded types)
import { Match } from "effect"
// Without is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.not(Match.string, (value) => `not string: ${value}`),
// At this point, type system uses Without<string> to track exclusion
Match.orElse(() => "was a string")
)
Without<function (type parameter) X in type Types.AddWithout<A, X>X | function (type parameter) WXWX>
: [function (type parameter) A in type Types.AddWithout<A, X>A] extends [interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<infer function (type parameter) OXOX>] ? interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) OXOX, function (type parameter) X in type Types.AddWithout<A, X>X>>
: never
/**
* Adds a type to the inclusion filter, refining what should be included.
*
* **Details**
*
* This utility type manages the refinement of included types during
* pattern matching. It ensures that only the most specific type
* constraints are maintained when multiple positive matches are applied.
*
* **Example** (Refining included types)
*
* ```ts
* import { Match } from "effect"
*
* // AddOnly is used when refining positive matches:
* Match.type<{ type: "user" | "admin"; name: string }>().pipe(
* Match.when({ type: "admin" }, (admin) => admin.name),
* // Type system uses AddOnly to refine the constraint
* Match.orElse(() => "not admin")
* )
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.AddOnly<A, X> = [A] extends [Without<infer WX>] ? [X] extends [WX] ? never : Only<X> : [A] extends [Only<infer OX>] ? [X] extends [OX] ? Only<X> : never : neverAdds a type to the inclusion filter, refining what should be included.
Details
This utility type manages the refinement of included types during
pattern matching. It ensures that only the most specific type
constraints are maintained when multiple positive matches are applied.
Example (Refining included types)
import { Match } from "effect"
// AddOnly is used when refining positive matches:
Match.type<{ type: "user" | "admin"; name: string }>().pipe(
Match.when({ type: "admin" }, (admin) => admin.name),
// Type system uses AddOnly to refine the constraint
Match.orElse(() => "not admin")
)
AddOnly<function (type parameter) A in type Types.AddOnly<A, X>A, function (type parameter) X in type Types.AddOnly<A, X>X> = [function (type parameter) A in type Types.AddOnly<A, X>A] extends [interface Types.Without<out X>Represents a filter that excludes specific types from a union.
Details
Without is used internally to track which types should be excluded
from consideration during pattern matching. It helps implement the
type-level logic for Match.not and other exclusion operations.
Example (Tracking excluded types)
import { Match } from "effect"
// Without is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.not(Match.string, (value) => `not string: ${value}`),
// At this point, type system uses Without<string> to track exclusion
Match.orElse(() => "was a string")
)
Without<infer function (type parameter) WXWX>] ? [function (type parameter) X in type Types.AddOnly<A, X>X] extends [function (type parameter) WXWX] ? never
: interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<function (type parameter) X in type Types.AddOnly<A, X>X>
: [function (type parameter) A in type Types.AddOnly<A, X>A] extends [interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<infer function (type parameter) OXOX>] ? [function (type parameter) X in type Types.AddOnly<A, X>X] extends [function (type parameter) OXOX] ? interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<function (type parameter) X in type Types.AddOnly<A, X>X>
: never
: never
/**
* Applies accumulated filters to an input type, producing the final narrowed type.
*
* **Details**
*
* This utility type takes the collected inclusion/exclusion filters and
* applies them to the input type to compute the final narrowed result.
* It's the culmination of the type-level filtering process.
*
* **Example** (Applying accumulated filters)
*
* ```ts
* import type { Match } from "effect"
*
* // ApplyFilters computes the final narrowed type:
* type Result = Match.Types.ApplyFilters<
* string | number | boolean,
* Match.Types.Only<string>
* >
* // Result: string
*
* type ExclusionResult = Match.Types.ApplyFilters<
* string | number | boolean,
* Match.Types.Without<string>
* >
* // Result: number | boolean
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.ApplyFilters<I, A> = A extends Only<infer X> ? X : A extends Without<infer X> ? Exclude<I, X> : neverApplies accumulated filters to an input type, producing the final narrowed type.
Details
This utility type takes the collected inclusion/exclusion filters and
applies them to the input type to compute the final narrowed result.
It's the culmination of the type-level filtering process.
Example (Applying accumulated filters)
import type { Match } from "effect"
// ApplyFilters computes the final narrowed type:
type Result = Match.Types.ApplyFilters<
string | number | boolean,
Match.Types.Only<string>
>
// Result: string
type ExclusionResult = Match.Types.ApplyFilters<
string | number | boolean,
Match.Types.Without<string>
>
// Result: number | boolean
ApplyFilters<function (type parameter) I in type Types.ApplyFilters<I, A>I, function (type parameter) A in type Types.ApplyFilters<I, A>A> = function (type parameter) A in type Types.ApplyFilters<I, A>A extends interface Types.Only<out X>Represents a filter that includes only specific types from a union.
Details
Only is used internally to track which types should be exclusively
considered during pattern matching. It helps implement the type-level
logic for positive matches and type narrowing.
Example (Tracking included types)
import { Match } from "effect"
// Only is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (s) => `string: ${s}`),
// At this point, type system uses Only<string> for the match
Match.orElse((value) => `not string: ${value}`)
)
Only<infer function (type parameter) XX> ? function (type parameter) XX
: function (type parameter) A in type Types.ApplyFilters<I, A>A extends interface Types.Without<out X>Represents a filter that excludes specific types from a union.
Details
Without is used internally to track which types should be excluded
from consideration during pattern matching. It helps implement the
type-level logic for Match.not and other exclusion operations.
Example (Tracking excluded types)
import { Match } from "effect"
// Without is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.not(Match.string, (value) => `not string: ${value}`),
// At this point, type system uses Without<string> to track exclusion
Match.orElse(() => "was a string")
)
Without<infer function (type parameter) XX> ? type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) I in type Types.ApplyFilters<I, A>I, function (type parameter) XX>
: never
/**
* Extracts tag values from a discriminated union based on a discriminant field.
*
* **Details**
*
* This utility type extracts the possible values of a discriminant field
* from a union type. It's used internally to implement tag-based pattern
* matching for discriminated unions.
*
* **Example** (Extracting discriminator tags)
*
* ```ts
* import type { Match } from "effect"
*
* type Events =
* | { _tag: "click"; x: number; y: number }
* | { _tag: "keypress"; key: string }
* | { _tag: "scroll"; delta: number }
*
* type EventTags = Match.Types.Tags<"_tag", Events>
* // Result: "click" | "keypress" | "scroll"
*
* type CustomTags = Match.Types.Tags<
* "type",
* | { type: "user"; name: string }
* | { type: "admin"; permissions: Array<string> }
* >
* // Result: "user" | "admin"
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.Tags<D extends string, P> = P extends Record<D, infer X> ? X : neverExtracts tag values from a discriminated union based on a discriminant field.
Details
This utility type extracts the possible values of a discriminant field
from a union type. It's used internally to implement tag-based pattern
matching for discriminated unions.
Example (Extracting discriminator tags)
import type { Match } from "effect"
type Events =
| { _tag: "click"; x: number; y: number }
| { _tag: "keypress"; key: string }
| { _tag: "scroll"; delta: number }
type EventTags = Match.Types.Tags<"_tag", Events>
// Result: "click" | "keypress" | "scroll"
type CustomTags = Match.Types.Tags<
"type",
| { type: "user"; name: string }
| { type: "admin"; permissions: Array<string> }
>
// Result: "user" | "admin"
Tags<function (type parameter) D in type Types.Tags<D extends string, P>D extends string, function (type parameter) P in type Types.Tags<D extends string, P>P> = function (type parameter) P in type Types.Tags<D extends string, P>P extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<function (type parameter) D in type Types.Tags<D extends string, P>D, infer function (type parameter) XX> ? function (type parameter) XX : never
/**
* Converts an array type to an intersection of its element types.
*
* **Details**
*
* This utility type takes an array of types and converts them into a single
* intersection type. It's used internally when multiple patterns need to
* be satisfied simultaneously (like in `Match.whenAnd`).
*
* **Example** (Converting arrays to intersections)
*
* ```ts
* import type { Match } from "effect"
*
* type Combined = Match.Types.ArrayToIntersection<[
* { name: string },
* { age: number },
* { active: boolean }
* ]>
* // Result: { name: string } & { age: number } & { active: boolean }
* // = { name: string; age: number; active: boolean }
*
* // This type utility enables complex type intersections
* // Complex type operations are handled by this utility type
* // for advanced pattern matching scenarios
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.ArrayToIntersection<A extends ReadonlyArray<any>> = (A[number] extends any ? (x: A[number]) => any : never) extends (x: infer R) => any ? R : neverConverts an array type to an intersection of its element types.
Details
This utility type takes an array of types and converts them into a single
intersection type. It's used internally when multiple patterns need to
be satisfied simultaneously (like in Match.whenAnd).
Example (Converting arrays to intersections)
import type { Match } from "effect"
type Combined = Match.Types.ArrayToIntersection<[
{ name: string },
{ age: number },
{ active: boolean }
]>
// Result: { name: string } & { age: number } & { active: boolean }
// = { name: string; age: number; active: boolean }
// This type utility enables complex type intersections
// Complex type operations are handled by this utility type
// for advanced pattern matching scenarios
ArrayToIntersection<function (type parameter) A in type Types.ArrayToIntersection<A extends ReadonlyArray<any>>A extends interface ReadonlyArray<T>ReadonlyArray<any>> = import TT.type UnionToIntersection<T> = (
T extends any ? (x: T) => any : never
) extends (x: infer R) => any
? R
: never
Transforms a union type into an intersection type.
When to use
Use to combine all members of a union into a single type with all their
properties. This is useful in advanced generic code where you need to merge
union variants.
Details
- Uses distributive conditional types and contra-variant inference.
- If the union members are incompatible (e.g.
string | number), the
result is never.
Example (Converting a union to an intersection)
import type { Types } from "effect"
type Union = { a: string } | { b: number }
type Result = Types.UnionToIntersection<Union>
// { a: string } & { b: number }
UnionToIntersection<
function (type parameter) A in type Types.ArrayToIntersection<A extends ReadonlyArray<any>>A[number]
>
/**
* Extracts and narrows the matched type from an input type given a pattern.
*
* **Details**
*
* This is the core type utility that performs the actual type extraction
* and narrowing logic. It handles the complex type-level computation that
* determines what type results from applying a pattern to an input type.
*
* **Example** (Extracting matched types)
*
* ```ts
* import { Match } from "effect"
*
* type StringExtract = Match.Types.ExtractMatch<
* string | number | boolean,
* typeof Match.string
* >
* // Result: string
*
* type ObjectExtract = Match.Types.ExtractMatch<
* { type: "user"; name: string } | { type: "admin"; role: string },
* { type: "user" }
* >
* // Result: { type: "user"; name: string }
*
* // This powers the type narrowing in:
* Match.when(Match.string, (s) => s.toUpperCase())
* // ^^^ s is correctly typed as string
* ```
*
* @category types
* @since 4.0.0
*/
export type type Types.ExtractMatch<I, P> = [ExtractAndNarrow<I, P>] extends [infer EI] ? EI : neverExtracts and narrows the matched type from an input type given a pattern.
Details
This is the core type utility that performs the actual type extraction
and narrowing logic. It handles the complex type-level computation that
determines what type results from applying a pattern to an input type.
Example (Extracting matched types)
import { Match } from "effect"
type StringExtract = Match.Types.ExtractMatch<
string | number | boolean,
typeof Match.string
>
// Result: string
type ObjectExtract = Match.Types.ExtractMatch<
{ type: "user"; name: string } | { type: "admin"; role: string },
{ type: "user" }
>
// Result: { type: "user"; name: string }
// This powers the type narrowing in:
Match.when(Match.string, (s) => s.toUpperCase())
// ^^^ s is correctly typed as string
ExtractMatch<function (type parameter) I in type Types.ExtractMatch<I, P>I, function (type parameter) P in type Types.ExtractMatch<I, P>P> = [type Types.ExtractAndNarrow<Input, P> = P extends Predicate.Refinement<infer _In, infer _Out extends infer _In> ? _Out extends Input ? Extract<_Out, Input> : Extract<Input, _Out> : P extends SafeRefinement<infer _In, infer _R> ? [0] extends [1 & _R] ? Input : _In extends Input ? Extract<_In, Input> : Extract<Input, _In> : P extends Predicate.Predicate<infer _In> ? Extract<Input, _In> : Input extends infer I ? Exclude<...> : neverExtractAndNarrow<function (type parameter) I in type Types.ExtractMatch<I, P>I, function (type parameter) P in type Types.ExtractMatch<I, P>P>] extends [infer function (type parameter) EIEI] ? function (type parameter) EIEI
: never
type type Types.Replace<A, B> = A extends Function ? A : A extends Record<string | number, any> ? { [K in keyof A]: K extends keyof B ? Replace<A[K], B[K]> : A[K]; } : [B] extends [A] ? B : AReplace<function (type parameter) A in type Types.Replace<A, B>A, function (type parameter) B in type Types.Replace<A, B>B> = function (type parameter) A in type Types.Replace<A, B>A extends Function ? function (type parameter) A in type Types.Replace<A, B>A
: function (type parameter) A in type Types.Replace<A, B>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string | number, any> ? { [function (type parameter) KK in keyof function (type parameter) A in type Types.Replace<A, B>A]: function (type parameter) KK extends keyof function (type parameter) B in type Types.Replace<A, B>B ? type Types.Replace<A, B> = A extends Function ? A : A extends Record<string | number, any> ? { [K in keyof A]: K extends keyof B ? Replace<A[K], B[K]> : A[K]; } : [B] extends [A] ? B : AReplace<function (type parameter) A in type Types.Replace<A, B>A[function (type parameter) KK], function (type parameter) B in type Types.Replace<A, B>B[function (type parameter) KK]> : function (type parameter) A in type Types.Replace<A, B>A[function (type parameter) KK] }
: [function (type parameter) B in type Types.Replace<A, B>B] extends [function (type parameter) A in type Types.Replace<A, B>A] ? function (type parameter) B in type Types.Replace<A, B>B
: function (type parameter) A in type Types.Replace<A, B>A
type type Types.MaybeReplace<I, P> = [P] extends [I] ? P : [I] extends [P] ? Replace<I, P> : typeof FailMaybeReplace<function (type parameter) I in type Types.MaybeReplace<I, P>I, function (type parameter) P in type Types.MaybeReplace<I, P>P> = [function (type parameter) P in type Types.MaybeReplace<I, P>P] extends [function (type parameter) I in type Types.MaybeReplace<I, P>I] ? function (type parameter) P in type Types.MaybeReplace<I, P>P
: [function (type parameter) I in type Types.MaybeReplace<I, P>I] extends [function (type parameter) P in type Types.MaybeReplace<I, P>P] ? type Types.Replace<A, B> = A extends Function ? A : A extends Record<string | number, any> ? { [K in keyof A]: K extends keyof B ? Replace<A[K], B[K]> : A[K]; } : [B] extends [A] ? B : AReplace<function (type parameter) I in type Types.MaybeReplace<I, P>I, function (type parameter) P in type Types.MaybeReplace<I, P>P>
: type Fail = typeof FailFail
type type Types.BuiltInObjects = Function | RegExp | Date | Generator<unknown, any, any> | {
readonly [Symbol.toStringTag]: string;
}
BuiltInObjects =
| Function
| Date
| RegExp
| interface Generator<T = unknown, TReturn = any, TNext = any>Generator
| { readonly [var Symbol: SymbolConstructorSymbol.SymbolConstructor.toStringTag: typeof Symbol.toStringTagA String value that is used in the creation of the default string description of an object.
Called by the built-in method Object.prototype.toString.
toStringTag]: string }
type type Types.IsPlainObject<T> = T extends BuiltInObjects ? false : T extends Record<string, any> ? true : falseIsPlainObject<function (type parameter) T in type Types.IsPlainObject<T>T> = function (type parameter) T in type Types.IsPlainObject<T>T extends type Types.BuiltInObjects = Function | RegExp | Date | Generator<unknown, any, any> | {
readonly [Symbol.toStringTag]: string;
}
BuiltInObjects ? false
: function (type parameter) T in type Types.IsPlainObject<T>T extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> ? true
: false
type type Types.Simplify<A> = { [K in keyof A]: A[K]; }Simplify<function (type parameter) A in type Types.Simplify<A>A> = { [function (type parameter) KK in keyof function (type parameter) A in type Types.Simplify<A>A]: function (type parameter) A in type Types.Simplify<A>A[function (type parameter) KK] } & {}
type type Types.ExtractAndNarrow<Input, P> = P extends Predicate.Refinement<infer _In, infer _Out extends infer _In> ? _Out extends Input ? Extract<_Out, Input> : Extract<Input, _Out> : P extends SafeRefinement<infer _In, infer _R> ? [0] extends [1 & _R] ? Input : _In extends Input ? Extract<_In, Input> : Extract<Input, _In> : P extends Predicate.Predicate<infer _In> ? Extract<Input, _In> : Input extends infer I ? Exclude<...> : neverExtractAndNarrow<function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input, function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P> = function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P extends import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<infer function (type parameter) _In_In, infer function (type parameter) _Out_Out> ?
function (type parameter) _Out_Out extends function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input ? type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) _Out_Out, function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input>
: type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input, function (type parameter) _Out_Out> :
function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P extends interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<infer function (type parameter) _In_In, infer function (type parameter) _R_R> ? [0] extends [1 & function (type parameter) _R_R] ? function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input
: function (type parameter) _In_In extends function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input ? type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) _In_In, function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input>
: type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input, function (type parameter) _In_In>
: function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P extends import PredicatePredicate.interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<infer function (type parameter) _In_In> ? type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input, function (type parameter) _In_In>
: function (type parameter) Input in type Types.ExtractAndNarrow<Input, P>Input extends infer function (type parameter) II ? type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<
function (type parameter) II extends interface ReadonlyArray<T>ReadonlyArray<any> ? function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P extends interface ReadonlyArray<T>ReadonlyArray<any> ? {
readonly [function (type parameter) KK in keyof function (type parameter) II]: function (type parameter) KK extends keyof function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P ? type Types.ExtractAndNarrow<Input, P> = P extends Predicate.Refinement<infer _In, infer _Out extends infer _In> ? _Out extends Input ? Extract<_Out, Input> : Extract<Input, _Out> : P extends SafeRefinement<infer _In, infer _R> ? [0] extends [1 & _R] ? Input : _In extends Input ? Extract<_In, Input> : Extract<Input, _In> : P extends Predicate.Predicate<infer _In> ? Extract<Input, _In> : Input extends infer I ? Exclude<...> : neverExtractAndNarrow<function (type parameter) II[function (type parameter) KK], function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P[function (type parameter) KK]>
: function (type parameter) II[function (type parameter) KK]
} extends infer function (type parameter) RR ? type Fail = typeof FailFail extends function (type parameter) RR[keyof function (type parameter) RR] ? never
: function (type parameter) RR
: never
: never
: type Types.IsPlainObject<T> = T extends BuiltInObjects ? false : T extends Record<string, any> ? true : falseIsPlainObject<function (type parameter) II> extends true ? string extends keyof function (type parameter) II ? function (type parameter) II extends function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P ? function (type parameter) II
: never
: symbol extends keyof function (type parameter) II ? function (type parameter) II extends function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P ? function (type parameter) II
: never
: type Types.Simplify<A> = { [K in keyof A]: A[K]; }Simplify<
& { [function (type parameter) RKRK in type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<keyof function (type parameter) II, keyof function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P>]-?: type Types.ExtractAndNarrow<Input, P> = P extends Predicate.Refinement<infer _In, infer _Out extends infer _In> ? _Out extends Input ? Extract<_Out, Input> : Extract<Input, _Out> : P extends SafeRefinement<infer _In, infer _R> ? [0] extends [1 & _R] ? Input : _In extends Input ? Extract<_In, Input> : Extract<Input, _In> : P extends Predicate.Predicate<infer _In> ? Extract<Input, _In> : Input extends infer I ? Exclude<...> : neverExtractAndNarrow<function (type parameter) II[function (type parameter) RKRK], function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P[function (type parameter) RKRK]> }
& type Omit<T, K extends keyof any> = {
[P in Exclude<keyof T, K>]: T[P]
}
Construct a type with the properties of T except for those in type K.
Omit<function (type parameter) II, keyof function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P>
> extends infer function (type parameter) RR ? keyof function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P extends type Types.NonFailKeys<A> = keyof A & {} extends infer K ? K extends keyof A ? A[K] extends typeof Fail ? never : K : never : neverNonFailKeys<function (type parameter) RR> ? function (type parameter) RR
: never
: never
: type Types.MaybeReplace<I, P> = [P] extends [I] ? P : [I] extends [P] ? Replace<I, P> : typeof FailMaybeReplace<function (type parameter) II, function (type parameter) P in type Types.ExtractAndNarrow<Input, P>P> extends infer function (type parameter) RR ? [function (type parameter) II] extends [function (type parameter) RR] ? function (type parameter) II
: function (type parameter) RR
: never,
type Fail = typeof FailFail
> :
never
type type Types.NonFailKeys<A> = keyof A & {} extends infer K ? K extends keyof A ? A[K] extends typeof Fail ? never : K : never : neverNonFailKeys<function (type parameter) A in type Types.NonFailKeys<A>A> = keyof function (type parameter) A in type Types.NonFailKeys<A>A & {} extends infer function (type parameter) KK ? function (type parameter) KK extends keyof function (type parameter) A in type Types.NonFailKeys<A>A ? function (type parameter) A in type Types.NonFailKeys<A>A[function (type parameter) KK] extends type Fail = typeof FailFail ? never : function (type parameter) KK
: never :
never
}