A type guard for vals that expect a WebApi Request as the first parameter.

Since a val can be invoked by run, web, express or even email, the correct type for a web endpoint should be req?: Request | unknown.

By using this type guard and handling the false case, all later code can safely access the request:

export const myVal = (req?: Request | unknown) => {
  if (!@karfau.isRequest(req)) {
    return `This val has to be used with the web endpoint, see ${@neverstew.thisValUrl()}`;
  if (req.method === 'GET') {
    // ...
export const isRequest = (req?: Request | unknown): req is Request =>
!!req && req instanceof Request;
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.