# Ag Referencia Typescript

> Patterns TypeScript strict mode, generics, utility types, e error handling

- **Type:** Skill
- **Install:** `agentstack add skill-andregusman-raiz-a-gusman-claude-ag-referencia-typescript`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [andregusman-raiz](https://agentstack.voostack.com/s/andregusman-raiz)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [andregusman-raiz](https://github.com/andregusman-raiz)
- **Source:** https://github.com/andregusman-raiz/a-gusman-claude/tree/main/archive/reference-skills-deprecated-2026-04-22/ag-referencia-typescript

## Install

```sh
agentstack add skill-andregusman-raiz-a-gusman-claude-ag-referencia-typescript
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Skill: TypeScript Patterns

Referencia de patterns para TypeScript em modo strict.

## Quando Ativar

- Definindo tipos complexos
- Usando generics
- Implementando error handling tipado
- Trabalhando com Zod e inferencia

## Strict Mode (tsconfig recomendado)

```json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitReturns": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true
  }
}
```

## Utility Types

```typescript
type UpdateUser = Partial;
type RequiredUser = Required;
type UserPreview = Pick;
type PublicUser = Omit;
type RolePermissions = Record;
type Config = Readonly;
type ServiceResult = ReturnType;
type Users = Awaited>;
```

## Generics

```typescript
function first(arr: T[]): T | undefined {
  return arr[0];
}

function getProperty(obj: T, key: K): T[K] {
  return obj[key];
}

interface ApiResponse {
  data: T;
  error: string | null;
  status: number;
}

interface Repository {
  findById(id: string): Promise;
  findAll(): Promise;
  create(input: CreateInput): Promise;
  update(id: string, input: UpdateInput): Promise;
  delete(id: string): Promise;
}
```

## Discriminated Unions

```typescript
type Result =
  | { success: true; data: T }
  | { success: false; error: E };

function divide(a: number, b: number): Result {
  if (b === 0) return { success: false, error: 'Divisao por zero' };
  return { success: true, data: a / b };
}

const result = divide(10, 2);
if (result.success) {
  console.log(result.data); // TypeScript sabe que e number
}
```

## Zod + TypeScript

```typescript
import { z } from 'zod';

const userSchema = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  name: z.string().min(1),
  role: z.enum(['admin', 'user', 'guest']),
});

type User = z.infer;

// Validacao segura
const result = userSchema.safeParse(rawData);
if (result.success) {
  const user = result.data; // Tipado corretamente
}
```

## Error Handling

```typescript
class AppError extends Error {
  constructor(
    message: string,
    public code: string,
    public statusCode: number = 500,
  ) {
    super(message);
    this.name = 'AppError';
  }
}

class NotFoundError extends AppError {
  constructor(resource: string, id: string) {
    super(`${resource} com id ${id} nao encontrado`, 'NOT_FOUND', 404);
  }
}

class ValidationError extends AppError {
  constructor(details: z.ZodError) {
    super('Dados invalidos', 'VALIDATION_ERROR', 400);
  }
}
```

## Type Guards

```typescript
function isUser(obj: unknown): obj is User {
  return typeof obj === 'object' && obj !== null && 'id' in obj && 'email' in obj;
}

function assertDefined(val: T | null | undefined, name: string): asserts val is T {
  if (val == null) throw new AppError(`${name} e obrigatorio`, 'ASSERTION_FAILED');
}
```

## Async Patterns

```typescript
// Promise.allSettled para operacoes independentes
const results = await Promise.allSettled([fetchUsers(), fetchPosts()]);
const users = results[0].status === 'fulfilled' ? results[0].value : [];

// Retry com backoff
async function withRetry(fn: () => Promise, maxRetries = 3, delay = 1000): Promise {
  for (let attempt = 0; attempt  setTimeout(r, delay * Math.pow(2, attempt)));
    }
  }
  throw new Error('Unreachable');
}
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [andregusman-raiz](https://github.com/andregusman-raiz)
- **Source:** [andregusman-raiz/a-gusman-claude](https://github.com/andregusman-raiz/a-gusman-claude)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-andregusman-raiz-a-gusman-claude-ag-referencia-typescript
- Seller: https://agentstack.voostack.com/s/andregusman-raiz
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
