Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • TypeScript Documentation28টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Introduction
  • Installation
  • Basic Types
  • Variables & Inference
  • Functions
  • Objects
  • Type Alias
  • Interface
  • Union & Intersection
  • Type Narrowing
  • Type Guards
  • Enums
  • Generics
  • Classes
  • Utility Types
  • Type Assertion
  • Async TypeScript
  • Conditional Types
  • Mapped Types
  • Template Literal Types
  • tsconfig Options
  • Modules & Types
  • Decorators
  • React + TypeScript
  • Node.js + TypeScript
  • JS → TypeScript
  • Common Errors
  • Mini Project
  1. Docs
  2. TypeScript
  3. Union ও Intersection Types
TypeScriptBeginner

Union ও Intersection Types

Union (|) এবং intersection (&) — literal union, object combine এবং এদের পার্থক্য — বাংলায় উদাহরণসহ।

13টি অংশবাংলা ভাষায়

Union type (|) মানে যেকোনো একটি, আর intersection type (&) মানে সবগুলো একসাথে। এই দুই অপারেটর মিলেই TypeScript-এর শক্তির মূল ভিত্তি।

Union Type

type ID = string | number;

function formatId(id: ID): string {
  return "ID: " + id;
}

console.log(formatId("a-1"));
console.log(formatId(42));

Union with Literal Types

type PaymentStatus = "pending" | "paid" | "failed";
type Result = "success" | "error";

function show(status: PaymentStatus): void {
  console.log(status);
}

show("paid");
// show("done");    // ❌ অনুমোদিত নয়

Intersection Type

Union মানে অথবা (একটা), Intersection মানে এবং (সবকিছু)। Intersection দিয়ে object টাইপ মিশিয়ে নতুন টাইপ বানানো হয়।

type User = {
  name: string;
};

type Admin = {
  role: string;
};

type AdminUser = User & Admin;

const boss: AdminUser = {
  name: "রহিম",
  role: "admin",
};

// boss-এ name ও role দুইটিই বাধ্যতামূলক

Combining Object Types

type BaseUser = {
  id: number;
  name: string;
};

type Premium = {
  premium: true;
  expiresAt: Date;
};

type PremiumUser = BaseUser & Premium;

const member: PremiumUser = {
  id: 1,
  name: "সুমন",
  premium: true,
  expiresAt: new Date("2026-12-31"),
};

Union vs Intersection

অপারেটরঅর্থউদাহরণ
| (Union)যেকোনো একটিstring | number
& (Intersection)সবগুলো একসাথেUser & Admin
| ব্যবহারসীমিত অপশন'paid' | 'pending'
& ব্যবহারকম্বাইন্ড objectBase & Extra
Union নিয়ে কাজের কৌশল

union পাওয়ার পর কোনো প্রপার্টি ব্যবহার করতে TypeScript narrowing চায় — typeof, in বা kind (discriminated union) দিয়ে টাইপ সরু করতে হয়। পরের অধ্যায়ে বিস্তারিত।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরInterface (ইন্টারফেস)পরেরType Narrowing (টাইপ ন্যারোয়িং)
এই পেজে
Tech Tutor

বাংলায় ওয়েব ডেভেলপমেন্ট ডকুমেন্টেশন শিখুন — ধাপে ধাপে।

Homeসব ডকুমেন্টেশনQuick Startআমার নোটস

© 2026 Tech Tutor. বাংলায় শিখুন, বাংলায় গড়ুন।

mdanamolhasan1998@gmail.com