Type Inference for Branded Schema in Effect Typescript Library

hi, is there any better way to do this? or is there already type in effect that does this?
/**
 * Infer the type of Brand symbol or string from the branded schema type.
 *
 * @example
 * type UserIdType = Brand.Branded<'id' | 'uuid', 'user_id'> // ('id' | 'uuid') & Brand.Brand<'user_id'>
 * type UserIdTypeSymbol = InferBrandedSchemaType<UserIdType> // 'user_id'
 *
 * @category Schema
 */
export type InferBrandedSchemaType<T> = T extends infer _V & Brand.Brand<infer K> ? K : never

/**
 * Infer the value of the branded schema type.
 * This is the actual value that is branded. For example, `uuid` in `uuid & Brand.Brand<'user_id'>`.
 *
 * @example
 * type UserIdType = Brand.Branded<'id' | 'uuid', 'user_id'> // ('id' | 'uuid') & Brand.Brand<'user_id'>
 * type UserIdTypeValue = InferBrandedSchemaValue<UserIdType> // 'id' | 'uuid'
 *
 * @category Schema
 */
export type InferBrandedSchemaValue<T> = T extends infer V & Brand.Brand<InferBrandedSchemaType<T>> ? V : never

/**
 * Type alias to define the branded schema value.
 *
 * @example
 * type UserIdType = Brand.Branded<'id' | 'uuid', 'user_id'> // ('id' | 'uuid') & Brand.Brand<'user_id'>
 * type UserUUID = BrandedSchemaValue<UserIdType, 'uuid'> // 'uuid' & Brand.Brand<'user_id'>
 *
 * @category Schema
 */
export type BrandedSchemaValue<T, V extends InferBrandedSchemaValue<T>> = Brand.Branded<V, InferBrandedSchemaType<T>>
Was this page helpful?