Skip to main content
Version: v9.0.0(Outdated)

Rules

The Hyper Fetch ESLint plugin includes several rules to help you catch common issues when working with Hyper Fetch. This page describes each rule, explains what it checks for, and provides examples of code that would trigger the rule.


What the rules accept​

  • Type references such as createRequest<RequestType>(). TypeScript already checks those against the constraint.
  • Intersections such as createRequest<GqlResponse<User> & { payload: Input }>(). Each object part is checked, and references inside the intersection are trusted.
  • Quoted keys such as { "response": User }, which count the same as { response: User }.

client-generic-types checks createClient imported from @hyper-fetch/core by name, alias or namespace, and allows the error key. request-generic-types allows response, payload, error, queryParams, endpoint and params, matching RequestGenericType in @hyper-fetch/core.


  1. client-generic-types​

This rule ensures proper generic types are used when creating clients with Hyper Fetch. It extends TypeScript's functionality to trace issues with object-like generic types that might otherwise be missed.

Description​

The rule checks for:

  • Unexpected generic type properties that don't match the expected interface
  • Empty generic type objects ({})
  • Generic types that don't match the expected object-like format

Examples of Issues Caught​

Unexpected generic type:

// ❌ Error: Unexpected generic type(s) found: nonExistingGenericType
import { createClient } from "@hyper-fetch/core";
const someClient = createClient<{ nonExistingGenericType: any }>({ url: "http://localhost:3000" });

Empty generic type:

// ❌ Error: Generic type provided to createClient is empty
import { createClient } from "@hyper-fetch/core";
const someClient = createClient<{}>({ url: "http://localhost:3000" });

Non-object-like generic type:

// ❌ Error: Generic type provided to createClient is not matching the expected object-like format
import { createClient } from "@hyper-fetch/core";
const someClient = createClient<unknown>({ url: "http://localhost:3000" });

Configuration​

Default severity: "error"


  1. request-generic-types​

This rule ensures proper generic types are used when creating requests with Hyper Fetch. It extends TypeScript's functionality to trace issues with object-like generic types that might otherwise be missed.

Description​

The rule checks for:

  • Unexpected generic type properties that don't match the expected interface
  • Empty generic type objects ({})
  • Generic types that don't match the expected object-like format

Examples of Issues Caught​

Unexpected generic type:

// ❌ Error: Unexpected generic type(s) found: nonExistingGenericType
import { client } from "./client";
const request = client.createRequest<{ nonExistingGenericType: any }>()({ endpoint: "/api/users" });

Empty generic type:

// ❌ Error: Generic type provided to createRequest is empty
import { client } from "./client";
const request = client.createRequest<{}>()({ endpoint: "/api/users" });

Non-object-like generic type:

// ❌ Error: Generic type provided to createRequest is not matching the expected object-like format
import { client } from "./client";
const request = client.createRequest<unknown>()({ endpoint: "/api/users" });

Configuration​

Default severity: "error"


When to Use These Rules​

These rules are particularly useful for:

  1. Large codebases where multiple developers might be working with Hyper Fetch
  2. Projects where type safety is critical
  3. Applications where you want to ensure consistent usage of Hyper Fetch
  4. Preventing subtle type-related bugs that might only manifest at runtime