import { HTMLAttributes } from 'vue'; /** * Gets all possible keys in a union. */ export type KeysOfUnion = T extends T ? keyof T : never; /** * Infer the value types of a record type */ export type RecordValues = T extends Record ? V : never; /** * Merge the values for all entries by key. */ export type UnionByKey = { [Key in T extends NonNullable ? keyof T : never]: T extends { [P in Key]?: infer Value; } ? Value extends undefined ? never : Value : never; }; /** * Merges two types destructively, right to left: * All keys from `Source` are kept as is and only the extraneous keys from `Target` that are not present in `Source` are copied over. * * @example * ```ts * type Result = Merge<{ a: number; b: string }, { b: boolean, c: unknown }> // => { a: number; b: boolean, c: unknown } * ``` */ export type Merge = { [P in Exclude]: Target[P]; } & (Source extends object ? Source : unknown); /** * Merges all types destructively from left to right: * For duplicated keys only the type from the right most occurring entry is kept. * * This is similar to the inferred type of a destructuring merge: `{ ...{ a: 1, b: "str" }, ...{ b: true }, ...{ b: 2 } }`. * * @example * ```ts * type Result = MergeAll<[{ a: number; b: string }, { b: boolean, c: unknown }, { b: number }]> // => { a: number; b: number, c: unknown } * ``` */ export type MergeAll = T extends [infer First, ...infer Rest] ? Rest extends [] ? First : Merge> : never; /** * Take the value types from `T` for the key `K`, if it exists. */ export type MaybeUnwrap = Key extends keyof T ? T[Key] : Fallback; /** * Create a subset of `T` for all keys `Key` that exist in `T` */ export type MaybePick = { [P in Key as P extends keyof T ? P : never]: P extends keyof T ? T[P] : never; }; /** * Recursive / deep implementation of TypeScript's built-in `Partial` type. */ export type DeepPartial = T extends object ? { [P in keyof T]?: DeepPartial; } : T; /** * Adds all native HTML attributes to the given type. */ export type WithHTMLAttributes = TAttributes & T; /** * Generic data object. */ export type Data = Record; /** * Simple Wrapper for extends type checking. * Returns the passed type if it extends the specified `Extends` type, and `Else` type otherwise. */ export type IfExtends = T extends Extends ? T : Else; /** * Returns the passed type if not empty, and `Else` type otherwise. */ export type IfNotEmpty = T extends Record ? Else : T; /** * Simple "Native"/"Primitive" JavaScript types, that do not wrap other types. */ export type PrimitiveType = null | number | string | boolean | symbol; /** * A type that can also be null or undefined. */ export type Nullable = T | undefined | null;