I would like to have a function that checks to see if X or Y is null, and if not, have TypeScript successfully narrow the types down. Is this possible?
const X: string | null
const Y: Record<string, Bar> | null
const checkNull = <T,>(cb:()=>T):T|null => !X || !Y ? null : cb()
const getBar = () => checkNull(()=> Y[X]) << currently says Y and X could be null