std
    Preparing search index...

    Function equalsOneOf

    • Returns the string that matches the string (if it exits). Great for matching string union types.

      Type Parameters

      • T extends string

      Parameters

      • str: string
      • strings: readonly T[]

      Returns undefined | T

      const methods = ['GET', 'PUT', 'POST', 'PATCH', 'DELETE'] as const;

      const methodStr: string = 'GET';

      const method = equalsOneOf(methodStr, methods);

      if (method) {
      // if method was just a string this would be a type error
      methods.includes(method)
      }