Command Palette

Search for a command to run...

Назад к скиллам
скилл № 22632

language

Guide for core TypeScript language features and the type system. Use when writing or reviewing TypeScript types, enabling strict mode, choosing a utility…

БесплатноБез исполняемых скриптов
vinnie357от vinnie357★ 30 звёзд на GitHub

Установить language в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

TypeScript Language

Core TypeScript: strict mode, the type system, utility types, declaration files, and discriminated unions.

Strict Mode

strict: true in tsconfig.json is the floor for new TypeScript code in this workspace, not an opt-in extra. It is a single flag that enables a family of component flags — turn it on first, then reach for a component flag only when you need something strict doesn't cover.

{
  "compilerOptions": {
    "strict": true
  }
}

strict enables, among others:

Flag What it catches
noImplicitAny A variable or parameter would be inferred as any because no annotation is present
strictNullChecks null/undefined stop being implicitly assignable to every type
strictFunctionTypes Function parameter types are checked contravariantly instead of bivariantly
strictBindCallApply .call/.bind/.apply are checked against the underlying function's signature
strictPropertyInitialization A class field must be assigned in the constructor or have a definite-assignment marker
noImplicitThis this inside a function with unclear context is flagged instead of defaulting to any
alwaysStrict Every emitted file is parsed as, and emits, ECMAScript strict mode
useUnknownInCatchVariables catch (e) types e as unknown, not any — forces a type check before use

Two flags strict does not enable — they are separate opt-ins the strict family does not imply, though a current tsc --init now writes both into a fresh project's generated tsconfig.json alongside strict: true (listed under its own "Stricter Typechecking Options" heading, not inside the strict block itself):

  • exactOptionalPropertyTypes — an optional property (foo?: string) rejects an explicit undefined assignment unless the type says foo?: string | undefined. Catches call sites that "clear" a field by writing undefined when the schema meant "omit it."
  • noUncheckedIndexedAccess — indexing into a Record<string, T> or array by a computed key returns T | undefined instead of T, since JavaScript doesn't guarantee the key exists.

Both close real holes; both also touch a large fraction of existing index/optional-property call sites when retrofitted onto an established codebase. For a new project, accept them as part of the scaffolded default rather than deleting them — that's what tsc --init on a current release now hands you. For an existing codebase without them, treat enabling them as its own reviewed migration, not a drive-by addition alongside an unrelated change.

The Type System

Generics

A generic function or class defers a type decision to its caller instead of committing to one type or widening to any:

function firstOf<T>(items: T[]): T | undefined {
  return items[0];
}

const n = firstOf([1, 2, 3]);        // T inferred as number
const s = firstOf<string>(["a"]);    // T explicit

Constrain a type parameter with extends when the function body needs to rely on a property existing:

interface HasLength {
  length: number;
}

function longest<T extends HasLength>(a: T, b: T): T {
  return a.length >= b.length ? a : b;
}

keyof combined with a second type parameter constrained to it is the standard shape for a type-safe property getter:

function get<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}

Generic classes are generic only over their instance side — a static member cannot reference the class's own type parameter.

Conditional types and infer

A conditional type picks between two branches based on an extends check evaluated at the type level:

type IsString<T> = T extends string ? true : false;

infer introduces a type variable inside the extends clause and captures whatever the checked type matched there — this is how library-authored utility types extract a piece of a larger type:

type Flatten<T> = T extends Array<infer Item> ? Item : T;
type ElementOf<T extends readonly unknown[]> = T extends readonly (infer E)[] ? E : never;

Conditional types distribute over a union type parameter by default — Cond<A | B> evaluates as Cond<A> | Cond<B>. Wrap both sides in a tuple ([T] extends [U] ? ... : ...) to compare the union as one type instead of distributing across it. Distribution is usually what you want for a "filter this union" utility; non-distribution is what you want when the conditional is deciding between two shapes of the same aggregate type.

Mapped types and key remapping

A mapped type transforms every property of an existing type using the same rule:

type Readonly<T> = { readonly [K in keyof T]: T[K] };
type Partial<T> = { [K in keyof T]?: T[K] };

The as clause in a mapped type (TypeScript 4.1+) remaps the resulting key, not just its value — the standard shape for deriving a getter/setter interfa

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/type-system-deep-dive.md

FAQ

Что делает скилл language?

Guide for core TypeScript language features and the type system. Use when writing or reviewing TypeScript types, enabling strict mode, choosing a utility type, designing generics or conditional types, writing declaration files, or modeling data with discriminated unions.

Как установить скилл language?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл language запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить language с