Skip to main content Link Search Menu Expand Document (external link)

Identifier overview

Helpers for creating unique identifiers for Contextual implementations.

Oftentimes you won’t need to use these directly, as it is embedded in all of the Contextual implementations.

Added in v1.0.0


Table of contents


constructors

id

Construct a unique identifier for a Contextual implementation.

Signature

export declare function id<const T>(uniqueIdentifier: T): IdentifierConstructor<T>

Added in v1.0.0

models

Identifier (interface)

A unique identifier for a Contextual implementation.

Signature

export interface Identifier<T> {
  readonly __identifier__: T
}

Added in v1.0.0

IdentifierConstructor (interface)

A constructor for a unique identifier for a Contextual implementation.

Signature

export interface IdentifierConstructor<T> extends Identifier<T> {
  new (): Identifier<T>
}

Added in v1.0.0

IdentifierFactory (type alias)

A factory for creating a unique identifier for a Contextual implementation.

Signature

export type IdentifierFactory<T> = (_id: typeof id) => IdentifierConstructor<T>

Added in v1.0.0

IdentifierInput (type alias)

A factory, constructor, or instance of a unique identifier for a Contextual implementation.

Signature

export type IdentifierInput<T> = IdentifierFactory<T> | IdentifierConstructor<T> | T

Added in v1.0.0

type-level

IdentifierOf (type alias)

Extract the Identifier from a Contextual implementation.

Signature

export type IdentifierOf<T> = T extends (_id: typeof id) => IdentifierConstructor<infer _>
  ? InstanceType<ReturnType<T>>
  : // eslint-disable-next-line @typescript-eslint/no-unused-vars
    T extends IdentifierConstructor<infer _>
    ? InstanceType<T>
    : T

Added in v1.0.0

utils

identifierToString

Convert an identifier to a string.

Signature

export declare function identifierToString(x: unknown): string

Added in v1.0.0

makeIdentifier

Create an Identifier from a factory, constructor, or instance of an Identifier.

Signature

export declare function makeIdentifier<T>(input: IdentifierInput<T>): IdentifierOf<T>

Added in v1.0.0