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} />; }
Note the divRef.current!. For all its advanced capabilities, TypeScript does make it very easy for you to ignore its analysis!
divRef.current!
Ah, cool, thanks!
👍🏻 I've updated the article accordingly.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you know better than the typechecker, you can use
!
to assert that something will not be null or undefined:Note the
divRef.current!
. For all its advanced capabilities, TypeScript does make it very easy for you to ignore its analysis!Ah, cool, thanks!
👍🏻 I've updated the article accordingly.