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

推荐订阅源

IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
I
InfoQ
Jina AI
Jina AI
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
量子位
月光博客
月光博客
罗磊的独立博客
雷峰网
雷峰网
The Cloudflare Blog
V
V2EX
小众软件
小众软件
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题

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
TypeScript Survival Guide (Part 1): Stop Making These Mis...
Noriuki · 2026-04-29 · via DEV Community

If you're coming from JavaScript, TypeScript can feel overwhelming at first.

Suddenly, you have types, errors, and things that didn’t exist before.

This is a simple survival guide to help you avoid the most common mistakes.

1. Avoid using any

When I first started using TypeScript, I used any everywhere.

let value: any = "hello"

Enter fullscreen mode Exit fullscreen mode

It works — but it defeats the whole purpose of TypeScript.

You're basically going back to plain JavaScript.

👉 Use any only when you really have no other option.


2. Prefer unknown over any

If you don’t know the type yet, use unknown.

let value: unknown = "hello"

Enter fullscreen mode Exit fullscreen mode

The difference is:

  • any lets you do anything (no safety)
  • unknown forces you to check the type first

Example:

function print(value: unknown) {
  if (typeof value === "string") {
    console.log(value.toUpperCase())
  }
}

Enter fullscreen mode Exit fullscreen mode

This makes your code safer and more predictable.


3. Always type your functions

JavaScript:

function sum(a, b) {
  return a + b
}

Enter fullscreen mode Exit fullscreen mode

TypeScript:

function sum(a: number, b: number): number {
  return a + b
}

Enter fullscreen mode Exit fullscreen mode

Now it's clear:

  • what the function expects
  • what it returns

4. Types are not just rules — they are documentation

Good types make your code easier to read.

type User = {
  name: string
  age: number
}

Enter fullscreen mode Exit fullscreen mode

Now anyone can understand your data structure instantly.


5. Learn type narrowing (this is more important than it looks)

TypeScript can "narrow" types based on checks you write.

Example:

function print(value: string | number) {
  if (typeof value === "string") {
    console.log(value.toUpperCase())
  } else {
    console.log(value.toFixed(2))
  }
}

Enter fullscreen mode Exit fullscreen mode

Even though value can be multiple types,

TypeScript understands what it is inside each block.

This is called type narrowing.

👉 This is what makes TypeScript actually smart — not just strict.


Final thoughts

TypeScript is not just about avoiding errors.

It's about writing clearer, more predictable code.

At first, it might feel slower.

But once you get used to it, it becomes hard to go back to JavaScript without types.