Skip to content

PrimaryKey

The PrimaryKey module defines a small protocol for values that can expose a stable, string-based identifier. A value participates by implementing a method at symbol; consumers can check unknown values with isPrimaryKey and read the key with value.

4 exports Added in v2.0.0 Source

Getters

value

Added in v2.0.0 Source

Extracts the string value from a PrimaryKey.

When to use

Use to read the stable string identifier from a value that implements PrimaryKey.

Signature

declare function value(self: PrimaryKey): string;

Guards

isPrimaryKey

Added in v4.0.0 Source

Checks whether a value implements the PrimaryKey protocol.

When to use

Use to narrow an unknown value before treating it as a PrimaryKey.

Details

This is a structural guard for the PrimaryKey.symbol property.

Gotchas

This guard does not call the method or verify that it returns a string.

See

  • PrimaryKey for the protocol being checked
  • value for extracting the string value after narrowing

Signature

declare function isPrimaryKey(u: unknown): u is PrimaryKey;

Models

PrimaryKey interface

Added in v2.0.0 Source

An interface for objects that can provide a string-based primary key.

When to use

Use to define values that expose a stable string identifier for equality, hashing, caching, or persistence.

Details

Objects implementing this interface must provide a method that returns a unique string identifier.

Signature

interface PrimaryKey {
  "~effect/interfaces/PrimaryKey"(): string;
}

Symbols

symbol

Added in v2.0.0 Source

Defines the unique identifier used to identify objects that implement the PrimaryKey interface.

When to use

Use to implement the PrimaryKey protocol as a computed property key on classes or object literals that expose a stable string identifier.

See

  • PrimaryKey for the protocol interface that declares the method keyed by this symbol
  • value for reading the string key from a PrimaryKey value
  • isPrimaryKey for checking whether an unknown value carries this method

Signature

declare const symbol: "~effect/interfaces/PrimaryKey";