export type MergeableRefCallback = { bivarianceHack(node: T | null): void | (() => void); }['bivarianceHack']; export type MergeableRefObject = { current: T | null }; export type MergeableVueRef = { value: T | null }; export type RefProp = (node: T | null) => void | (() => void); export type RefValue = | ((node: T) => void | (() => void)) | readonly RefValue[] | { current: T | null } | { value: T | null } | T | null | undefined; export type MergeableRef = MergeableRefCallback | MergeableRefObject | MergeableVueRef | null | undefined; /** * A props bag as it reaches a spread: keys the caller has not narrowed. * * Accepting bag is spelled `object` at the parameter position — an index * signature would reject an interface- or class-typed props bag — while this * is what the helpers hand back when they rebuild one. */ export type SpreadProps = Record; /** * The node a ref value points at, derived from the ref's own type in the order * the runtime resolves it (see `apply_ref_value` and `ref_object_prop`): a list * resolves through its entries, a callback through its parameter, and a DOM * node is never treated as a ref object. * * Inferring through `RefValue` instead would read the target off the wrong * union member: TypeScript prefers a structural member over a naked type * parameter, so `HTMLInputElement` would match the `{ value: T | null }` * (Vue ref) branch and resolve `T` to `string`. */ export type RefTarget = [V] extends [never] ? never : V extends null | undefined ? never : V extends (node: infer N) => unknown ? N : V extends readonly (infer E)[] ? RefTarget : V extends Node ? V : V extends { current: infer C } ? NonNullable : V extends { value: infer C } ? NonNullable : V; export function mergeRefs( ...refs: Array> ): (node: T | null) => () => void; export function isRefProp(value: unknown): boolean; // The inference overload comes first so an inferred call resolves the target // through `RefTarget`; the `T` overload below still serves explicit type // arguments, which is what every compiler-generated call passes. export function create_ref_prop( get_ref_value: () => V, set_ref_value?: (value: RefTarget | null) => void, ): RefProp>; export function create_ref_prop( get_ref_value: () => RefValue, set_ref_value?: (value: T | null) => void, ): RefProp; export function apply_ref_value( ref_value: V, node: RefTarget | null, set_ref_value?: (value: RefTarget | null) => void, ): void | (() => void); export function apply_ref_value( ref_value: RefValue, node: T | null, set_ref_value?: (value: T | null) => void, ): void | (() => void); export function merge_ref_props(...refs: Array>): RefValue; export function normalize_spread_props( props: T, ...outer_refs: Array> ): T | SpreadProps; export function normalize_spread_props_for_ref_attr( props: T, ...outer_refs: Array> ): T | SpreadProps;