<R extends Record<string, Predicate.Any>>(fields: R): [
Extract<R[keyof R], Refinement.Any>
] extends [never]
? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]> }>
: Refinement<
{
readonly [K in keyof R]: R[K] extends Refinement.Any
? Refinement.In<R[K]>
: Predicate.In<R[K]>
},
{
readonly [K in keyof R]: R[K] extends Refinement.Any
? Refinement.Out<R[K]>
: Predicate.In<R[K]>
}
>Creates a predicate for objects by applying predicates to named properties.
When to use
Use when you want to validate a record shape at runtime by lifting property predicates into an object predicate.
Details
Returns a refinement if any field predicate is a refinement. Only the specified keys are checked, and extra keys are ignored.
Example (Checking structs)
import { Predicate } from "effect"
const userCheck = Predicate.Struct({
id: Predicate.isNumber,
name: Predicate.isString
})
console.log(userCheck({ id: 1, name: "Ada" }))export function function Struct<
R extends Record<string, Predicate.Any>
>(
fields: R
): [Extract<R[keyof R], Refinement.Any>] extends [
never
]
? Predicate<{
readonly [K in keyof R]: Predicate.In<R[K]>
}>
: Refinement<
{
readonly [K in keyof R]: R[K] extends Refinement.Any
? Refinement.In<R[K]>
: Predicate.In<R[K]>
},
{
readonly [K in keyof R]: R[K] extends Refinement.Any
? Refinement.Out<R[K]>
: Predicate.In<R[K]>
}
>
Creates a predicate for objects by applying predicates to named properties.
When to use
Use when you want to validate a record shape at runtime by lifting property
predicates into an object predicate.
Details
Returns a refinement if any field predicate is a refinement. Only the
specified keys are checked, and extra keys are ignored.
Example (Checking structs)
import { Predicate } from "effect"
const userCheck = Predicate.Struct({
id: Predicate.isNumber,
name: Predicate.isString
})
console.log(userCheck({ id: 1, name: "Ada" }))
Struct<function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R 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, Predicate.type Predicate<in A>.Any = Predicate<any>A utility type representing any predicate type.
When to use
Use when you need a constraint for "any predicate" in generic code.
Details
This is type-only and creates no runtime value.
Example (Using generic constraints)
import { Predicate } from "effect"
type AnyPredicate = Predicate.Predicate.Any
Any>>(
fields: R extends Record<string, Predicate.Any>fields: function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R
): [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 Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[keyof function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R], Refinement.type Refinement<in A, out B extends A>.Any = Refinement<any, any>A utility type representing any refinement type.
When to use
Use when you need a constraint for "any refinement" in generic code.
Details
This is type-only and creates no runtime value.
Example (Using generic constraints)
import { Predicate } from "effect"
type AnyRefinement = Predicate.Refinement.Any
Any>] extends [never] ? 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<{ readonly [function (type parameter) KK in keyof function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R]: Predicate.type Predicate<in A>.In<T extends Predicate.Any> = [T] extends [Predicate<infer _A>] ? _A : neverExtracts the input type A from a Predicate<A>.
When to use
Use when you want to infer the input type from a predicate type while
defining generic utilities over predicates.
Details
This is type-only and creates no runtime value. It resolves to never if
the type does not match Predicate.
Example (Inferring the input type)
import { Predicate } from "effect"
type P = Predicate.Predicate<number>
type Input = Predicate.Predicate.In<P>
In<function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK]> }> :
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<
{ readonly [function (type parameter) KK in keyof function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R]: function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK] extends Refinement.type Refinement<in A, out B extends A>.Any = Refinement<any, any>A utility type representing any refinement type.
When to use
Use when you need a constraint for "any refinement" in generic code.
Details
This is type-only and creates no runtime value.
Example (Using generic constraints)
import { Predicate } from "effect"
type AnyRefinement = Predicate.Refinement.Any
Any ? Refinement.type Refinement<in A, out B extends A>.In<T extends Refinement.Any> = [T] extends [Refinement<infer _A, infer _ extends infer _A>] ? _A : neverExtracts the input type A from a Refinement<A, B>.
When to use
Use when you want to infer the input type from a refinement type.
Details
This is type-only and creates no runtime value. It resolves to never if
the type does not match Refinement.
Example (Inferring the input type)
import { Predicate } from "effect"
type R = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<R>
In<function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK]> : Predicate.type Predicate<in A>.In<T extends Predicate.Any> = [T] extends [Predicate<infer _A>] ? _A : neverExtracts the input type A from a Predicate<A>.
When to use
Use when you want to infer the input type from a predicate type while
defining generic utilities over predicates.
Details
This is type-only and creates no runtime value. It resolves to never if
the type does not match Predicate.
Example (Inferring the input type)
import { Predicate } from "effect"
type P = Predicate.Predicate<number>
type Input = Predicate.Predicate.In<P>
In<function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK]> },
{ readonly [function (type parameter) KK in keyof function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R]: function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK] extends Refinement.type Refinement<in A, out B extends A>.Any = Refinement<any, any>A utility type representing any refinement type.
When to use
Use when you need a constraint for "any refinement" in generic code.
Details
This is type-only and creates no runtime value.
Example (Using generic constraints)
import { Predicate } from "effect"
type AnyRefinement = Predicate.Refinement.Any
Any ? Refinement.type Refinement<in A, out B extends A>.Out<T extends Refinement.Any> = [T] extends [Refinement<infer _, infer _B extends infer _>] ? _B : neverExtracts the output type B from a Refinement<A, B>.
When to use
Use when you want to infer the narrowed type from a refinement type.
Details
This is type-only and creates no runtime value. It resolves to never if
the type does not match Refinement.
Example (Inferring the output type)
import { Predicate } from "effect"
type R = Predicate.Refinement<unknown, string>
type Output = Predicate.Refinement.Out<R>
Out<function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK]> : Predicate.type Predicate<in A>.In<T extends Predicate.Any> = [T] extends [Predicate<infer _A>] ? _A : neverExtracts the input type A from a Predicate<A>.
When to use
Use when you want to infer the input type from a predicate type while
defining generic utilities over predicates.
Details
This is type-only and creates no runtime value. It resolves to never if
the type does not match Predicate.
Example (Inferring the input type)
import { Predicate } from "effect"
type P = Predicate.Predicate<number>
type Input = Predicate.Predicate.In<P>
In<function (type parameter) R in Struct<R extends Record<string, Predicate.Any>>(fields: R): [Extract<R[keyof R], Refinement.Any>] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In<R[K]>; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In<R[K]> : Predicate.In<R[K]>; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out<R[K]> : Predicate.In<R[K]>; }>R[function (type parameter) KK]> }
>
{
const const keys: string[]keys = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.keys(o: {}): string[] (+1 overload)Returns the names of the enumerable string properties and methods of an object.
keys(fields: R extends Record<string, Predicate.Any>fields)
return ((a: Record<string, unknown>a: 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, unknown>) => {
for (const const key: stringkey of const keys: string[]keys) {
if (!fields: R extends Record<string, Predicate.Any>fields[const key: stringkey](a: Record<string, unknown>a[const key: stringkey] as never)) {
return false
}
}
return true
}) as any
}