I have written a wrapper that basically exposes a ref to the parent component. When I am trying to use the ref using typescript it throws the following error property does not exist on type
. This is how I exposing the ref
export interface IType{
name: string;
age: number;
}
export type TypeRef = MutableRefObject<{ getCurrentType: () => IType }>;
Basically in the parent , I am trying to use it this way
const typeRef = useRef<TypeRef>();
// Somewhere in the code
const testFunc = () => {
// below line throws Property 'getCurrentType' does not exist on type 'TypeRef'.ts(2339)
typeRef?.current?.getCurrentType();
}
How can I access this getType()
with proper type definitions? Basically this ref would return me a function that returns the current type