#How to prevent lexical error in build?

1 messages · Page 1 of 1 (latest)

thick lagoon
#

@sudden sluice I'm not sure there really is a way to catch this - in a lot of cases it'd be fine to access the return value from within the callback. It's only a problem because useMemo executes its callback synchronously, which is an implementation detail of useMemo.

#
function callAsync(cb: () => void) {
  setTimeout(cb, 0);
  return 0;
}

function callSync(cb: () => void) {
  cb();
  return 0;
}

const x = callAsync(() => console.log(x)); // okay
const y = callSync(() => console.log(y)) // runtime error
#

There's no way to know just by looking at the call site to know if this is safe or not.