37 lines
1.4 KiB
Plaintext
37 lines
1.4 KiB
Plaintext
import { Ref, MutableRefObject } from 'react';
|
|
|
|
interface Props {
|
|
[key: string]: any;
|
|
}
|
|
type PropsArg = Props | null | undefined;
|
|
type TupleTypes<T> = {
|
|
[P in keyof T]: T[P];
|
|
} extends {
|
|
[key: number]: infer V;
|
|
} ? NullToObject<V> : never;
|
|
type NullToObject<T> = T extends null | undefined ? {} : T;
|
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
/**
|
|
* Calls all functions in the order they were chained with the same arguments.
|
|
*/
|
|
declare function chain(...callbacks: any[]): (...args: any[]) => void;
|
|
declare let idsUpdaterMap: Map<string, {
|
|
current: string | null;
|
|
}[]>;
|
|
/**
|
|
* Merges two ids.
|
|
* Different ids will trigger a side-effect and re-render components hooked up with `useId`.
|
|
*/
|
|
declare function mergeIds(idA: string, idB: string): string;
|
|
/**
|
|
* Merges multiple props objects together. Event handlers are chained,
|
|
* classNames are combined, and ids are deduplicated - different ids
|
|
* will trigger a side-effect and re-render components hooked up with `useId`.
|
|
* For all other props, the last prop object overrides all previous ones.
|
|
* @param args - Multiple sets of props to merge together.
|
|
*/
|
|
declare function mergeProps<T extends PropsArg[]>(...args: T): UnionToIntersection<TupleTypes<T>>;
|
|
declare function mergeRefs<T>(...refs: Array<Ref<T> | MutableRefObject<T> | null | undefined>): Ref<T>;
|
|
|
|
export { chain, idsUpdaterMap, mergeIds, mergeProps, mergeRefs };
|