@glideapps/ts-necessities
    Preparing search index...

    Type Alias BrandedString<T>

    BrandedString: string & { __brand: T }

    A branded string is a string that has a unique type, so that it can be distinguished from other strings. This is useful when you want to ensure that a string is only used in a specific context. When assigning to a branded string type it's not allowed to assign a non-branded string, or a string of the wrong brand:

    type Apple = BrandedString<"apple">;
    type Orange = BrandedString<"orange">;

    const apple: Apple = brandString("Pink Lady");
    let orange: Orange = apple; // error!
    orange = "jalapeƱo"; // error!
    let justAString: string = apple; // This is ok

    Type Parameters

    • T extends string