CtrlK
BlogDocsLog inGet started
Tessl Logo

pantheon-ai/typescript-advanced

Comprehensive TypeScript guidance covering compiler configuration, advanced types, utility types, type guards, strict mode workflows, and documentation patterns; use when configuring tsconfig, designing complex generics, making illegal states unrepresentable, fixing type errors, or writing testable and maintainable type-safe APIs.

Overall
score

99%

Does it follow best practices?

Validation for skill structure

Overview
Skills
Evals
Files

practices-type-first.mdreferences/

Type-First Development

Type-first development means defining types before implementation. This workflow ensures type safety from the start and lets the compiler guide completeness.

Workflow

  1. Define the data model - types, interfaces, and schemas first
  2. Define function signatures - input/output types before logic
  3. Implement to satisfy types - let the compiler guide completeness
  4. Validate at boundaries - runtime checks where data enters the system

Example: API Endpoint Type-First

// 1. Define data model first
interface User {
  id: string;
  email: string;
  name: string;
  createdAt: Date;
}

type CreateUserRequest = Omit<User, 'id' | 'createdAt'>;
type UpdateUserRequest = Partial<CreateUserRequest>;

// 2. Define function signatures
async function createUser(req: CreateUserRequest): Promise<User>;
async function updateUser(id: string, req: UpdateUserRequest): Promise<User>;
async function getUser(id: string): Promise<User | null>;

// 3. Implement to satisfy types
async function createUser(req: CreateUserRequest): Promise<User> {
  const id = crypto.randomUUID();
  const createdAt = new Date();
  const user: User = { ...req, id, createdAt };
  await db.users.insert(user);
  return user;
}

Benefits

  • Compiler catches missing cases - Exhaustiveness checking on switch statements
  • IDE provides autocomplete - Types guide what properties/methods are available
  • Refactoring is safer - Type errors show all affected code
  • Documentation is built-in - Types serve as contracts
  • Runtime errors reduced - Many bugs caught at compile time

Type-First vs Code-First

Code-First (avoid):

// Implementation first, types inferred
function processData(data) {
  if (data.status === 'active') {
    return data.items.map(i => i.value);
  }
  return [];
}

Type-First (preferred):

// Types first, implementation second
type Status = 'active' | 'inactive';

interface DataItem {
  value: number;
}

interface Data {
  status: Status;
  items: DataItem[];
}

function processData(data: Data): number[] {
  if (data.status === 'active') {
    return data.items.map(i => i.value);
  }
  return [];
}

Integration with Runtime Validation

Types are compile-time only. Use Zod to bridge compile and runtime:

import { z } from 'zod';

// Schema as source of truth
const UserSchema = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  name: z.string().min(1),
  createdAt: z.date(),
});

// Infer TypeScript type from schema
type User = z.infer<typeof UserSchema>;

// Validate at runtime boundaries
function parseUser(data: unknown): User {
  return UserSchema.parse(data);
}

When to Define Types

  • Domain models - Always define first
  • API contracts - Define before implementing endpoints
  • Complex business logic - Define input/output types first
  • Library exports - Public API types defined first
  • Internal utilities - Can rely on type inference for simple helpers

References

  • TypeScript Handbook - Type Inference
  • Zod Documentation

Install with Tessl CLI

npx tessl i pantheon-ai/typescript-advanced@0.1.1

references

compiler-module-resolution.md

compiler-performance.md

compiler-strict-mode.md

compiler-tsconfig.md

docs-adr-templates.md

docs-framework-docs.md

docs-jsdoc-patterns.md

docs-typedoc-config.md

guards-assertion-functions.md

guards-basic.md

guards-branded-types.md

guards-discriminated-unions.md

guards-exhaustiveness.md

guards-generic.md

guards-inference-infer.md

guards-inference-return.md

patterns-advanced-generics.md

patterns-api-client.md

patterns-branded-types.md

patterns-builder.md

patterns-deep-readonly.md

patterns-dependency-injection.md

patterns-event-emitter.md

patterns-form-validation.md

patterns-plugin-system.md

patterns-recursive-types.md

patterns-state-machine.md

patterns-type-safe-module.md

practices-illegal-states.md

practices-module-patterns.md

practices-runtime-validation.md

practices-type-first.md

types-conditional.md

types-generics.md

types-index-signatures.md

types-mapped.md

types-narrowing.md

types-template-literals.md

types-type-assertions.md

types-unions-intersections.md

utilities-custom-mapped-types.md

utilities-extract-exclude.md

utilities-key-remapping.md

utilities-nonnullable-awaited.md

utilities-partial-required.md

utilities-pick-omit.md

utilities-readonly-record.md

utilities-returntype-parameters.md

SKILL.md

tile.json