DEV Community

Discussion on: TypeScript All the Things!

Collapse
 
crabmusket profile image
Daniel Buckmaster

If you know better than the typechecker, you can use ! to assert that something will not be null or undefined:

export default function MindMap({ data }: Props) {
  const divRef: RefObject<HTMLDivElement> = createRef();
  useEffect(() => {
    renderMindMap(divRef.current!, data);
  }, [divRef, data]);
  return <div ref={divRef} />;
}
Enter fullscreen mode Exit fullscreen mode

Note the divRef.current!. For all its advanced capabilities, TypeScript does make it very easy for you to ignore its analysis!

Collapse
 
pahund profile image
Patrick Hund

Ah, cool, thanks!

Collapse
 
pahund profile image
Patrick Hund

👍🏻 I've updated the article accordingly.