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. Enums (এনাম)
TypeScriptIntermediate

Enums (এনাম)

Numeric ও string enum, enum ব্যবহার, const enum এবং কখন enum অপেক্ষা অন্য পদ্ধতি ভালো — বাংলায়।

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

Enum দিয়ে নামকৃত ধ্রুবকের (named constants) একটি গ্রুপ বানানো যায় — যেমন status, direction, role। এতে কোড পঠনযোগ্য ও ভুলের সম্ভাবনা কমে।

Numeric Enum

enum Direction {
  Up,       // 0
  Down,     // 1
  Left,     // 2
  Right,    // 3
}

// নিজে start দিলে বাকিগুলো ক্রমে বাড়ে
enum Status {
  Pending = 1,
  Active = 5,
  Blocked,     // 6
}

console.log(Direction.Up);      // 0
console.log(Status.Blocked);    // 6

String Enum

enum Color {
  Primary = "primary",
  Secondary = "secondary",
  Danger = "danger",
}

const badge: Color = Color.Primary;
console.log(badge);    // "primary"

Enum ব্যবহার

enum Role {
  Admin = "admin",
  Editor = "editor",
  Viewer = "viewer",
}

function canEdit(role: Role): boolean {
  return role === Role.Admin || role === Role.Editor;
}

console.log(canEdit(Role.Admin));    // true
console.log(canEdit(Role.Viewer));   // false

const enum

const enum compile-এর সময় সরাসরি মান বসিয়ে দেয় — runtime-এ object রেখে যায় না। ফলে পারফরম্যান্স ভালো, তবে isolatedModules-এর মতো কিছু সেটিং-এ সীমাবদ্ধতা আছে।

const enum Size {
  Small = 10,
  Medium = 20,
  Large = 30,
}

// output-এ অদৃশ্য — সরাসরি 20 বসে যায়
const current = Size.Medium;
enum নাকি const object?

আধুনিক TS-এ প্রায়ই const obj = {...} as const + union preferable হয় — enum-এর বিশ্বস্ত behavior (reverse mapping) সব সেটিংয়ে কাজ নাও করতে পারে। ছোট-মাঝারি ক্ষেত্রে উভয়ই গ্রহণযোগ্য।

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

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

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

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

mdanamolhasan1998@gmail.com