TS2722: Cannot invoke an object which is possibly 'undefined'. createEffect(() => { if (drawerIsOpen() && viewportSizeProvider.viewPortIsLessThan1210) { createPreventScroll(); incrementPreventScrollLayerCount(); } }); Just add a ! if you’re sure func is never undefined createEffect(() => { if (drawerIsOpen() && viewportSizeProvider.viewPortIsLessThan1210) { createPreventScroll(); incrementPreventScrollLayerCount!(); // <--- ! } });