devtypes - v1.1.0
    Preparing search index...

    Type Alias Brand<Base, Tag, Key, Required>

    Brand: Base & If<
        Required,
        { readonly [K in Key]: Tag },
        { readonly [K in Key]?: Tag },
    >

    Brand a type for nominal typing.

    Type Parameters

    • Base

      Base type to brand

    • Tag extends string

      Unique string literal identifying the brand

    • Key extends string = "__brand"

      Property name used as the brand marker (defaults to __brand)

    • Required extends boolean = false

      Whether the marker is required (defaults to false)

    Creates a nominally distinct type by intersecting a base type with a readonly marker property. This prevents accidental mixing of otherwise structurally compatible types.

    type UserID = Brand< number, 'UserID' >;
    const id: UserID = 123 as UserID;