diff --git a/arcjet/index.ts b/arcjet/index.ts index f2f7425de..36e0b8f55 100644 --- a/arcjet/index.ts +++ b/arcjet/index.ts @@ -168,13 +168,14 @@ type LiteralCheck< | boolean | symbol | bigint, -> = IsNever extends false // Must be wider than `never` - ? [T] extends [LiteralType] // Must be narrower than `LiteralType` - ? [LiteralType] extends [T] // Cannot be wider than `LiteralType` - ? false - : true - : false - : false; +> = + IsNever extends false // Must be wider than `never` + ? [T] extends [LiteralType] // Must be narrower than `LiteralType` + ? [LiteralType] extends [T] // Cannot be wider than `LiteralType` + ? false + : true + : false + : false; type IsStringLiteral = LiteralCheck; export interface RemoteClient { @@ -586,20 +587,21 @@ export type Product = ArcjetRule[]; // Note: If a user doesn't provide the object literal to our primitives // directly, we fallback to no required props. They can opt-in by adding the // `as const` suffix to the characteristics array. -type PropsForCharacteristic = IsStringLiteral extends true - ? T extends - | "ip.src" - | "http.host" - | "http.method" - | "http.request.uri.path" - | `http.request.headers["${string}"]` - | `http.request.cookie["${string}"]` - | `http.request.uri.args["${string}"]` - ? {} - : T extends string - ? Record - : never - : {}; +type PropsForCharacteristic = + IsStringLiteral extends true + ? T extends + | "ip.src" + | "http.host" + | "http.method" + | "http.request.uri.path" + | `http.request.headers["${string}"]` + | `http.request.cookie["${string}"]` + | `http.request.uri.args["${string}"]` + ? {} + : T extends string + ? Record + : never + : {}; // Rules can specify they require specific props on an ArcjetRequest type PropsForRule = R extends ArcjetRule ? Props : {}; // We theoretically support an arbitrary amount of rule flattening, diff --git a/arcjet/test/index.node.test.ts b/arcjet/test/index.node.test.ts index b1865c592..8a8ba2de5 100644 --- a/arcjet/test/index.node.test.ts +++ b/arcjet/test/index.node.test.ts @@ -83,17 +83,15 @@ import arcjet, { // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -type IsEqual = (() => G extends A ? 1 : 2) extends () => G extends B - ? 1 - : 2 - ? true - : false; +type IsEqual = + (() => G extends A ? 1 : 2) extends () => G extends B ? 1 : 2 + ? true + : false; // Type testing utilities type Assert = T; -type Props

= P extends Primitive - ? Props - : never; +type Props

= + P extends Primitive ? Props : never; type RequiredProps

= IsEqual, E>; // Instances of Headers contain symbols that may be different depending