Tipos
TypedResponse<T>
Estende Response com um metodo json() tipado:
typescript
interface TypedResponse<T> extends Response {
json(): Promise<T>;
}ClientErrors
Union de todas as 29 instancias de erro de cliente (4xx):
typescript
type ClientErrors =
| BadRequestError
| UnauthorizedError
| NotFoundError
// ... all 29 client error classesServerErrors
Union de todas as 11 instancias de erro de servidor (5xx):
typescript
type ServerErrors =
| InternalServerError
| BadGatewayError
| ServiceUnavailableError
// ... all 11 server error classesHttpErrors
Tipo construtor para qualquer classe de erro HTTP:
typescript
type HttpErrors = (typeof httpErrors)[number];TypedFetchError
Union de todos os tipos de erro possiveis retornados por typedFetch:
typescript
type TypedFetchError = HttpErrors | NetworkError;HttpMethods
Union de todas as strings de metodos HTTP padrao:
typescript
type HttpMethods =
| "GET" | "POST" | "PUT" | "PATCH" | "DELETE"
| "HEAD" | "OPTIONS" | "CONNECT" | "TRACE";StrictHeaders
Tipo de cabecalhos HTTP com IntelliSense para nomes de cabecalhos comuns e valores tipados:
typescript
type StrictHeaders = {
"Content-Type"?: "application/json" | "text/plain" | ...;
Authorization?: `${string} ${string}`;
Accept?: "application/json" | "*/*" | ...;
"Cache-Control"?: "no-cache" | "no-store" | ...;
// ... 30+ common headers with typed values
[key: string]: string | undefined; // custom headers allowed
};TypedHeaders
Aceita tanto StrictHeaders (com IntelliSense) quanto HeadersInit puro:
typescript
type TypedHeaders = StrictHeaders | HeadersInit;Tipo de Retorno Discriminated Union
typedFetch retorna uma discriminated union — verificar error restringe ambos os campos:
typescript
const { response, error } = await typedFetch<User>('/api/users');
if (error === null) {
// TypeScript sabe: response e TypedResponse<User>
const user = await response.json(); // Type: User
} else {
// TypeScript sabe: response e null
// error e ClientErrors | ServerErrors | NetworkError
}Com erros de cliente especificos:
typescript
const { response, error } = await typedFetch<User, NotFoundError>('/api/users/1');
if (error !== null) {
// error e NotFoundError | ServerErrors | NetworkError
}