/** * Utility type that extracts the value type from a Set type. * * This helper type uses conditional type inference to extract the element type * from a Set. It's useful when working with sets in type definitions where you * need to reference the type of elements contained within the set. * * The type uses TypeScript's `infer` keyword to capture the generic parameter * of the Set type, making it reusable across different Set types. * * @example * ```ts * import { SetValue } from '@tldraw/tlschema' * * // Extract value type from a Set type * type StringSet = Set * type StringValue = SetValue // string * * type NumberSet = Set * type NumberValue = SetValue // number * ``` * * @example * ```ts * // Usage with const sets * const COLORS = new Set(['red', 'green', 'blue'] as const) * type ColorSet = typeof COLORS * type Color = SetValue // 'red' | 'green' | 'blue' * * // Function that accepts set values * function processColor(color: SetValue) { * // color is typed as 'red' | 'green' | 'blue' * console.log(`Processing color: ${color}`) * } * ``` * * @example * ```ts * // Complex usage with union types * const UI_COLORS = new Set(['selection-stroke', 'accent', 'muted']) * type UIColorSet = typeof UI_COLORS * type UIColor = SetValue // 'selection-stroke' | 'accent' | 'muted' * * // Validate color is in set * function isValidUIColor(color: string): color is UIColor { * return UI_COLORS.has(color) * } * ``` * * @public */ export type SetValue> = T extends Set ? U : never