惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
MyScale Blog
MyScale Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Last Week in AI
Last Week in AI
罗磊的独立博客
G
Google Developers Blog
Y
Y Combinator Blog
博客园 - 【当耐特】
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
美团技术团队
宝玉的分享
宝玉的分享
Jina AI
Jina AI
小众软件
小众软件
T
Tailwind CSS Blog
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
From Zero to Hero in TypeScript
Mía Salazar · 2026-06-20 · via DEV Community
Cover image for From Zero to Hero in TypeScript

Mía Salazar

TypeScript has become the go-to language for writing scalable, safer JavaScript in large applications. With its powerful static typing and developer tooling, it allows you to catch bugs earlier and write more expressive code.

This guide walks you through the journey, starting from the very basics and gradually moving toward intermediate and advanced TypeScript concepts.

What is TypeScript?

TypeScript is a superset of JavaScript that adds static typing. It compiles down to plain JavaScript, but offers better tooling, type safety, and developer confidence.

The Basics: Understanding the Type System

The basic types of Typescript are:

  • number: whole and floating numbers
  • boolean:true or false values
  • string: text values
  • symbol: globally unique identifier.
  • bigint: whole numbers allowing larger negative and positive numbers than the standard number type.

Type Annotations

let name: string = "Alice";
let age: number = 30;
let isOnline: boolean = true;

Any
any disables type checking and allows all types.

let name: any = true;
name = "Taylor"; 
Math.round(name);

Arrays and Objects

let fruits: string[] = ["apple", "banana"];

let user: { name: string; age: number } = {
  name: "Bob",
  age: 25
};

Functions

function greet(name: string): string {
  return `Hello, ${name}`;
}

void
void indicates that a function doesn't return any value.

function someFunction(): void {
  console.log('This is an article');
}

Intermediate Features: Making Your Types Smarter

Type Aliases and Interfaces
Interfaces and type aliases are similar, but interfaces are generally used for objects and support declaration merging.

type User = {
  id: number;
  username: string;
};

interface Product {
  id: number;
  title: string;
  price: number;
}

Optional and Readonly Properties

interface Config {
  url: string;
  timeout?: number; // optional
  readonly port: number;
}

Enum

enum Direction {
  Up,
  Down,
  Left,
  Right
}

Tuples
A tuple is an array with a pre-defined types and length.

let tuple: [string, boolean, number];
tuple = ['hello", true, 22];

Literal Types & Narrowing
Literal types allow you to specify the exact value a variable can hold.

function handleEvent(event: "click" | "scroll") {}

Union and Intersection Types
Union types let a variable be one of several types, while intersection types combine multiple types into one that must satisfy all of them.

type UserState = { status: "success" | "error" | "loading" };
type WithTimestamp = { timestamp: number };

type LogEntry = UserState & WithTimestamp; 
// Ahora LogEntry tiene tanto 'status' como 'timestamp'

Advanced & Practical Techniques

Generics
Generics allow you to write reusable code with type flexibility

function identity<T>(value: T): T {
  return value;
}

const num = identity<number>(42);
const str = identity("hello");

Utility Types
TypeScript provides built-in utilities like

type Partial<T>       // Makes all properties optional
type Pick<T, K>       // Picks a subset of properties
type Record<K, T>     // Builds object types from keys and values
type Exclude<T, U>    // Removes a type from a union

Discriminated Unions
Useful for handling different types with shared structure

type Shape =
  | { kind: "circle"; radius: number }
  | { kind: "square"; size: number };

Type Guards

function isString(value: unknown): value is string {
  return typeof value === "string";
}

Casting with as
as informs the compiler to treat a variable as a specific type, without altering the actual runtime object.

type User = {
  name: string;
  age: number;
};

const data = {
  name: "Alice",
  age: 30,
  role: "admin"
};

const user = data as User;

Tips & Best Practices

  • Prefer type for aliases and primitives, and interface for object shapes and components.
  • Don’t overuse any, it defeats the purpose of TypeScript.
  • Use unknown instead of any when input type is truly uncertain.
  • Let the compiler infer where possible, but annotate for clarity in APIs.

Conclusion

TypeScript offers a powerful type system on top of JavaScript that makes your codebase safer, clearer, and more maintainable. By starting with the basics and gradually adopting more advanced features like generics, utility types, and type guards, you’ll gain confidence in architecting scalable front-end and back-end solutions.