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

compiler-strict-mode.mdreferences/

TypeScript Strict Mode

Overview

"strict": true enables all strict type checking options. It's the foundation of type-safe TypeScript.

Strict Mode Flags

Core Flags (enabled by strict)

noImplicitAny - Disallow implicit any types

// Error with noImplicitAny
function greet(name) { // Parameter 'name' implicitly has an 'any' type
  console.log(`Hello, ${name}`);
}

// Fix: Add explicit type
function greet(name: string) {
  console.log(`Hello, ${name}`);
}

strictNullChecks - null and undefined require explicit handling

// Error with strictNullChecks
function getLength(str: string | null) {
  return str.length; // Object is possibly 'null'
}

// Fix: Check for null
function getLength(str: string | null) {
  return str?.length ?? 0;
}

strictFunctionTypes - Stricter checking of function parameter types

type Handler = (value: string) => void;
type GenericHandler = (value: string | number) => void;

// Error: Type 'GenericHandler' is not assignable to 'Handler'
const handler: Handler = (value: string | number) => {};

strictBindCallApply - Check bind, call, and apply arguments

function greet(name: string, age: number) {
  console.log(`${name} is ${age} years old`);
}

greet.call(undefined, "Alice", "30"); // Error: Argument of type 'string' not assignable to 'number'

strictPropertyInitialization - Ensure class properties are initialized

class User {
  name: string; // Error: Property 'name' has no initializer
  age: number = 0; // OK: Has initializer
  email!: string; // OK: Definite assignment assertion
  
  constructor() {
    this.name = ""; // OK: Initialized in constructor
  }
}

noImplicitThis - Disallow implicit any for this

// Error with noImplicitThis
const obj = {
  name: "Alice",
  greet() {
    return function() {
      console.log(this.name); // 'this' implicitly has type 'any'
    };
  }
};

// Fix: Use arrow function
const obj = {
  name: "Alice",
  greet() {
    return () => {
      console.log(this.name); // OK: Arrow function captures 'this'
    };
  }
};

alwaysStrict - Emit "use strict" in generated JavaScript

  • Enables JavaScript strict mode
  • Prevents common pitfalls (e.g., accidental globals)

Additional Recommended Flags

noUnusedLocals - Error on unused local variables

function calculate() {
  const x = 10; // Error: 'x' is declared but never used
  return 5;
}

noUnusedParameters - Error on unused function parameters

function greet(name: string, age: number) { // Error: 'age' is declared but never used
  console.log(`Hello, ${name}`);
}

// Fix: Prefix with underscore
function greet(name: string, _age: number) {
  console.log(`Hello, ${name}`);
}

noImplicitReturns - Error if not all code paths return a value

function getStatus(value: number): string {
  if (value > 0) {
    return "positive";
  }
  // Error: Not all code paths return a value
}

// Fix: Handle all paths
function getStatus(value: number): string {
  if (value > 0) {
    return "positive";
  }
  return "non-positive";
}

noFallthroughCasesInSwitch - Error on switch fallthrough

function getDay(day: number): string {
  switch (day) {
    case 0:
      return "Sunday";
    case 1: // Error: Fallthrough case in switch
      console.log("Monday");
    case 2:
      return "Tuesday";
  }
  return "Unknown";
}

noUncheckedIndexedAccess - Index signatures return T | undefined

const colors: Record<string, string> = { red: "#ff0000" };

// Without noUncheckedIndexedAccess
const red = colors["red"]; // Type: string

// With noUncheckedIndexedAccess
const red = colors["red"]; // Type: string | undefined
if (red) {
  console.log(red.toUpperCase()); // Safe
}

exactOptionalPropertyTypes - Distinguish undefined from missing

interface Config {
  timeout?: number;
}

// Without exactOptionalPropertyTypes
const config: Config = { timeout: undefined }; // OK

// With exactOptionalPropertyTypes
const config: Config = { timeout: undefined }; // Error
const config: Config = {}; // OK

Migration Strategy

Enabling strict mode in an existing codebase:

  1. Enable flags incrementally
{
  "compilerOptions": {
    "noImplicitAny": true,
    // Fix errors, then enable next flag
    "strictNullChecks": true,
    // Continue until all strict flags enabled
  }
}
  1. Use @ts-expect-error for temporary suppression
// @ts-expect-error TODO: Fix null handling
const value = maybeNull.property;
  1. Fix by priority

    • Start with noImplicitAny (easiest)
    • Then strictNullChecks (most impactful)
    • Finally other flags
  2. Use strictNullChecks migration helpers

// Option 1: Non-null assertion (use sparingly)
const value = maybeNull!.property;

// Option 2: Optional chaining
const value = maybeNull?.property;

// Option 3: Nullish coalescing
const value = maybeNull ?? defaultValue;

Benefits

  • Catch errors at compile time - Before runtime
  • Better IDE support - More accurate autocomplete
  • Self-documenting code - Types show intent
  • Easier refactoring - Type errors guide changes
  • Prevent null reference errors - strictNullChecks catches most

Best Practices

  1. Enable strict mode in new projects - Start with "strict": true
  2. Enable noUncheckedIndexedAccess - Not included in strict but highly recommended
  3. Enable exactOptionalPropertyTypes - Clearer optional semantics
  4. Use unknown over any - Forces type checking
  5. Avoid ! assertions - Prefer explicit null checks
  6. Add JSDoc for complex types - Helps other developers

Common Pitfalls

  • Using as any to bypass errors - Defeats purpose of strict mode
  • Overusing ! assertions - Hides potential null errors
  • Not enabling noUncheckedIndexedAccess - Still allows unsafe index access
  • Disabling strict for quick fixes - Technical debt accumulates

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