diff --git a/src/hooks.ts b/src/hooks.ts index 3deaafbd..24d42a2d 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -94,12 +94,12 @@ export const onWillUpdateProps = makeAsyncHook("willUpdatePropsCB"); * The purpose of this hook is to allow components to get a reference to a sub * html node or component. */ -interface Ref { +interface Ref { el: HTMLElement | null; - comp: Component | null; + comp: C | null; } -export function useRef(name: string): Ref { +export function useRef(name: string): Ref { const __owl__ = Component.current!.__owl__; return { get el(): HTMLElement | null { @@ -111,9 +111,9 @@ export function useRef(name: string): Ref { } return null; }, - get comp(): Component | null { + get comp(): C | null { const val = __owl__.refs && __owl__.refs[name]; - return val instanceof Component ? val : null; + return val instanceof Component ? (val as C) : null; }, }; } diff --git a/tests/hooks.test.ts b/tests/hooks.test.ts index 2ef79a6d..2b594c27 100644 --- a/tests/hooks.test.ts +++ b/tests/hooks.test.ts @@ -267,7 +267,7 @@ describe("hooks", () => { class WidgetC extends Component { static template = xml`
Hello
`; static components = { WidgetB }; - ref = useRef("mywidgetb"); + ref = useRef("mywidgetb"); } const widget = new WidgetC();