0

I have a variable that holds a Group Reference and when I call getClientRect() it returns the "IReact" type.

Since IReact is not in the default types index should I import the type from the internal types file or is there a better approach?

Simplified code reference:

import { IRect } from './../../../node_modules/konva/types/types';

const groupRef: React.RefObject<Konva.Group> = React.createRef();
const groupAttrsAux: IRect | undefined = groupRef.current?.getClientRect(null);
Gustavo Morais
  • 548
  • 6
  • 17

1 Answers1

2

You should never import from node_modules. Shouldn't this work?

import { IRect } from "konva/types/types";

tokland
  • 66,169
  • 13
  • 144
  • 170
  • Yes it does, thanks for the warning. Is this the best way to solve this situation then? Simply import IRect directly? – Gustavo Morais Jul 12 '20 at 21:10
  • 1
    Yes, it's exported in the package for you to import. Of course, you could fully re-define the type yourself, or use `ReturnType` on `typeof getClientRect`, but that would be ugly and unnecessary. – tokland Jul 12 '20 at 22:29