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

patterns-type-safe-module.mdreferences/

Type-Safe Module Pattern

Create modules with full type safety and encapsulation.

Basic Module Pattern

// math.ts
export interface MathOperations {
  add(a: number, b: number): number;
  subtract(a: number, b: number): number;
}

const createMath = (): MathOperations => {
  // Private implementation
  const cache = new Map<string, number>();
  
  const getCacheKey = (op: string, a: number, b: number) =>
    `${op}:${a}:${b}`;
  
  return {
    add(a, b) {
      const key = getCacheKey('add', a, b);
      if (!cache.has(key)) {
        cache.set(key, a + b);
      }
      return cache.get(key)!;
    },
    subtract(a, b) {
      const key = getCacheKey('sub', a, b);
      if (!cache.has(key)) {
        cache.set(key, a - b);
      }
      return cache.get(key)!;
    }
  };
};

export const math = createMath();

Plugin Architecture

interface Plugin<TConfig = unknown> {
  name: string;
  version: string;
  init(config: TConfig): Promise<void>;
  cleanup(): Promise<void>;
}

interface PluginRegistry {
  register<TConfig>(plugin: Plugin<TConfig>): void;
  get<TConfig>(name: string): Plugin<TConfig> | undefined;
  unregister(name: string): void;
}

const createPluginRegistry = (): PluginRegistry => {
  const plugins = new Map<string, Plugin>();
  
  return {
    register(plugin) {
      if (plugins.has(plugin.name)) {
        throw new Error(`Plugin ${plugin.name} already registered`);
      }
      plugins.set(plugin.name, plugin);
    },
    get(name) {
      return plugins.get(name);
    },
    unregister(name) {
      const plugin = plugins.get(name);
      if (plugin) {
        plugin.cleanup();
        plugins.delete(name);
      }
    }
  };
};

Module with Private State

export type UserId = string & { readonly __brand: 'UserId' };

export interface UserModule {
  create(email: string): UserId;
  get(id: UserId): { id: UserId; email: string } | undefined;
  delete(id: UserId): boolean;
}

const createUserModule = (): UserModule => {
  let counter = 0;
  const users = new Map<UserId, { id: UserId; email: string }>();
  
  const createUserId = (): UserId => {
    return `user-${++counter}` as UserId;
  };
  
  return {
    create(email) {
      const id = createUserId();
      users.set(id, { id, email });
      return id;
    },
    get(id) {
      return users.get(id);
    },
    delete(id) {
      return users.delete(id);
    }
  };
};

export const userModule = createUserModule();

Best Practices

  1. Export only interfaces: Keep implementation details private
  2. Use branded types: Prevent ID mixing across modules
  3. Single instance: Export one instance, not the factory
  4. Clear boundaries: Define what's public vs private
  5. Testability: Allow dependency injection for testing

Install with Tessl CLI

npx tessl i pantheon-ai/typescript-advanced

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