<K extends string | symbol>(key: NoInfer<K>): <A>(
self: ReadonlyRecord<K, A>
) => boolean
<K extends string | symbol, A>(
self: ReadonlyRecord<K, A>,
key: NoInfer<K>
): booleanChecks whether a given key exists in a record.
Example (Checking key membership)
import { Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Record.has({ a: 1, b: 2 }, "a"), true)
assert.deepStrictEqual(Record.has(Record.empty<string>(), "c"), false)export const const has: {
<K extends string | symbol>(key: NoInfer<K>): <
A
>(
self: ReadonlyRecord<K, A>
) => boolean
<K extends string | symbol, A>(
self: ReadonlyRecord<K, A>,
key: NoInfer<K>
): boolean
}
Checks whether a given key exists in a record.
Example (Checking key membership)
import { Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Record.has({ a: 1, b: 2 }, "a"), true)
assert.deepStrictEqual(Record.has(Record.empty<string>(), "c"), false)
has: {
<function (type parameter) K in <K extends string | symbol>(key: NoInfer<K>): <A>(self: ReadonlyRecord<K, A>) => booleanK extends string | symbol>(
key: NoInfer<K>key: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) K in <K extends string | symbol>(key: NoInfer<K>): <A>(self: ReadonlyRecord<K, A>) => booleanK>
): <function (type parameter) A in <A>(self: ReadonlyRecord<K, A>): booleanA>(self: ReadonlyRecord<K, A>self: type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<function (type parameter) K in <K extends string | symbol>(key: NoInfer<K>): <A>(self: ReadonlyRecord<K, A>) => booleanK, function (type parameter) A in <A>(self: ReadonlyRecord<K, A>): booleanA>) => boolean
<function (type parameter) K in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanK extends string | symbol, function (type parameter) A in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanA>(
self: ReadonlyRecord<K, A>self: type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<function (type parameter) K in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanK, function (type parameter) A in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanA>,
key: NoInfer<K>key: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) K in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanK>
): boolean
} = import dualdual(
2,
<function (type parameter) K in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanK extends string | symbol, function (type parameter) A in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanA>(
self: ReadonlyRecord<K, A>self: type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<function (type parameter) K in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanK, function (type parameter) A in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanA>,
key: NoInfer<K>key: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) K in <K extends string | symbol, A>(self: ReadonlyRecord<K, A>, key: NoInfer<K>): booleanK>
): boolean => var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.hasOwn(o: object, v: PropertyKey): booleanDetermines whether an object has a property with the specified name.
hasOwn(self: ReadonlyRecord<K, A>self, key: NoInfer<K>key)
)