Skip to content

Commit

Permalink
Migrate typing util to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 23, 2023
1 parent 85e5c81 commit a6125c1
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/util/typing.js → src/util/typing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* @template T
* @typedef {import('preact').Ref<T>} Ref
*/
import type { Ref } from 'preact';

/**
* Helper for downcasting a ref to a more specific type, where that is safe
Expand All @@ -10,12 +7,7 @@
* 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(ref) {
return /** @type {Ref<U>|undefined} */ (ref);
export function downcastRef<T, U>(ref: Ref<T> | undefined): Ref<U> | undefined {
return ref as Ref<U> | undefined;
}

0 comments on commit a6125c1

Please sign in to comment.