/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { UsageError } from "@fluidframework/telemetry-utils/internal";
/**
 * Helper for {@link Brand}.
 *
 * See `MakeNominal` for some more details.
 *
 * Do not use this class with `instanceof`: this will always be false at runtime,
 * but the compiler may think it's true in some cases.
 *
 * @remarks
 * This is covariant over ValueType.
 * This is suitable for when ValueType is immutable (like string or number),
 * which is the common use-case for branding.
 *
 * @privateRemarks
 * This is split out into its own type as that's the only way to:
 *
 * - make the member protected (so you can't accidentally try and access it).
 * - get nominal typing (so types produced without using this class can never be assignable to it).
 *
 * @sealed
 * @internal
 */
export class BrandedType {
    /**
     * This class should never exist at runtime, so make it un-constructable.
     */
    constructor() { }
    /**
     * Since this class is a compile time only type brand, `instanceof` will never work with it.
     * This `Symbol.hasInstance` implementation ensures that `instanceof` will error if used,
     * and in TypeScript 5.3 and newer will produce a compile time error if used.
     */
    static [Symbol.hasInstance](value) {
        throw new UsageError("BrandedType is a compile time type brand not a real class that can be used with `instancof` at runtime.");
    }
}
/**
 * Adds a type {@link Brand} to a value.
 *
 * Only do this when specifically allowed by the requirements of the type being converted to.
 * @privateRemarks
 * Leaving `T` unconstrained here allows for better type inference when branding unions.
 * For example when assigning `brand(number)` a number to an optional branded number field,
 * constraining T to `BrandedType<unknown, string>` causes the inference to fail and requires explicitly providing the type parameter.
 * For example leaving T unconstrained instead allows the union of `BrandedType | undefined` to distribute over the conditional allowing the branding only the the union members which should be branded.
 * This does not permit branding an optional value into an optional field since non branded union members are still excluded from input to this function:
 * this is an intended restriction as it causes compile errors for misuse of this function (like using brand when the relevant type is not a branded type).
 * @internal
 */
export function brand(value) {
    return value;
}
//# sourceMappingURL=brand.js.map