UNPKG

@hypothesis/frontend-shared

Version:

Shared components, styles and utilities for Hypothesis projects

20 lines (19 loc) 671 B
/** * @template T * @typedef {import('preact').Ref<T>} Ref */ /** * Helper for downcasting a ref to a more specific type, where that is safe * to do. * * This is mainly useful to cast a generic `Ref<HTMLElement>` to a more specific * element type (eg. `Ref<HTMLDivElement>`) for use with the `ref` prop of a JSX element. * Since Preact only writes to the `ref` prop, such a cast is safe. * * @template T * @template {T} U * @param {Ref<T>|undefined} ref * @return {Ref<U>|undefined} */ export function downcastRef<T, U extends T>(ref: import("preact").Ref<T> | undefined): import("preact").Ref<U> | undefined; export type Ref<T> = import('preact').Ref<T>;