typescript
TypeScript Skill (2025-2026 Edition)
This skill outlines the latest best practices for writing robust, performant, and type-safe TypeScript code, aligned with the 2025-2026 ecosystem (TypeScript 5.x and beyond).
π Key Trends & Features (2025/2026)
- Native Speed: The transition to a Go-based compiler (native port) is underway (TS 7+), promising massive performance gains.
- Default Strictness: Modern projects treat
strict: trueas the absolute baseline. - Framework First: TS is now deeply integrated into frameworks (Next.js, Remix, NestJS) rather than an add-on.
π οΈ Configuration Best Practices (tsconfig.json)
Use strict defaults to prevent bugs before they happen.
{
"compilerOptions": {
/* Type Safety */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"noUncheckedIndexedAccess": true, /* 2025 Essential: Prevents accessing undefined array indices */
"exactOptionalPropertyTypes": true, /* Stricter optional property checks */
/* Modules & Emit */
"module": "NodeNext", /* or "ESNext" for pure frontend */
"moduleResolution": "NodeNext", /* Aligns with modern Node.js ESM */
"target": "ES2022", /* Modern runtimes support recent ES features */
"skipLibCheck": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"verbatimModuleSyntax": true, /* Enforces strict import/export syntax (TS 5.0+) */
/* Developer Experience */
"allowSyntheticDefaultImports": true
}
}
π§© Type Safety & Patterns
1. unknown over any
Never use any unless absolutely necessary (e.g., migrating legacy code). Use unknown and narrow the type safely.
// β Bad
function processData(input: any) {
input.doSomething(); // Runtime crash risk
}
// β
Good
function processData(input: unknown) {
if (typeof input === 'string') {
console.log(input.toUpperCase()); // Safe
} else if (isCustomType(input)) {
input.doSomething(); // Safe via type guard
}
}
2. satisfies Operator (TS 4.9+)
Use satisfies to validate a value matches a type without widening the type (preserving inference).
type Config = Record<string, string | number>;
const myConfig = {
port: 8080,
host: "localhost"
} satisfies Config;
// β
TS knows 'port' is a number directly, no casting needed.
myConfig.port.toFixed(2);
3. Immutable Data by Default
Use readonly to prevent accidental mutations, especially for function arguments and React props.
interface User {
readonly id: string;
readonly name: string;
tags: readonly string[]; // Immutable array
}
function printTags(tags: readonly string[]) {
// tags.push("new"); // β Error: Property 'push' does not exist on type 'readonly string[]'
}
4. Template Literal Types
Create precise string types for better autocompletion and safety.
type EventName = "click" | "hover";
type HandlerName = `on${Capitalize<EventName>}`; // "onClick" | "onHover"
β‘ Performance Optimization
- Type Imports: Use
import type { ... }orimport { type ... }explicitly. EnablingverbatimModuleSyntaxenforces this, ensuring zero JS overhead for type-only imports using modern bundlers. - Lazy Loading: Leverage
await import(...)for splitting code in large applications.
β οΈ Common Pitfalls to Avoid
- Excessive Type Assertions (
as): Use type guards orzodfor validation instead of forcing types withas. - Broad Types: Avoid
Functionorobject. Use() => voidorRecord<string, unknown>instead. - Enum Misuse: Prefer union types of strings (
type Status = 'open' | 'closed') over standard TSenums to keep runtime code cleaner and avoid nominal typing surprises.
π References
More from toilahuongg/shopify-agents-kit
shopify-polaris-icons
Guide for using Shopify Polaris Icons in Shopify Apps. Covers icon usage patterns, accessibility, tone variants, and common icon categories for commerce applications.
19email-template-design
Design and build professional HTML email templates with inline CSS for broad email client compatibility. Use this skill when the user asks to create, design, or build email templates, newsletters, transactional emails (order confirmations, receipts, shipping notifications, password resets), marketing emails, welcome series, onboarding emails, abandoned cart emails, drip campaigns, or any HTML email layout. Covers responsive design, dark mode support, and compatibility with Gmail, Outlook (desktop + web), Apple Mail, Yahoo, and mobile clients.
18shopify-extensions
Guide for building and managing Shopify Extensions (Admin, Checkout, Theme, Post-purchase, etc.) using the latest Shopify CLI and APIs.
14shopify-api
Comprehensive guide for Shopify APIs in Remix apps. Covers Admin GraphQL/REST, Storefront API, all resources (products, orders, customers, inventory, collections, discounts, fulfillments, metafields, files), bulk operations, webhooks, resource pickers, and TypeScript patterns. Use when querying/mutating Shopify data or building integrations.
14shopify-polaris-viz
Guide for creating data visualizations in Shopify Apps using the Polaris Viz library. Use this skill when building charts, graphs, dashboards, or any data visualization components that need to integrate with the Shopify Admin aesthetic. Covers BarChart, LineChart, DonutChart, SparkLineChart, and theming.
13code-investigator
Comprehensive code investigation and audit tool. Discovers all project features, then dispatches parallel subagents to analyze issues, risks, dead code, missing functionality, and redundancies. Produces a prioritized risk report. Use this skill when the user asks to "investigate code", "audit project", "find risks", "check code quality", "analyze codebase", "what's wrong with this code", "project health check", "code review entire project", "find dead code", "find redundant code", or any request for a thorough codebase analysis.
11