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. TypeScript Objects (অবজেক্ট)
TypeScriptBeginner

TypeScript Objects (অবজেক্ট)

Object type annotation, optional ও readonly property, index signature, nested object এবং excess property checking — বাংলায়।

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

JavaScript-এ object সর্বত্র। TypeScript-এ object-এর গঠন টাইপ দিয়ে বাঁধা যায় — কোন প্রপার্টি আছে, কী ধরনের মান নেবে — সবই ঠিক করার আগে।

Object Type Annotation

const user: { name: string; age: number } = {
  name: "রহিম",
  age: 28,
};

// user.name = 999;    // ❌ string প্রত্যাশিত
// user.city = "ঢাকা"; // ❌ প্রপার্টি নেই

Optional Properties

const profile: { name: string; email?: string } = {
  name: "রহিম",
  // email দেওয়া বাধ্যতামূলক নয়
};

if (profile.email) {
  console.log(profile.email.toUpperCase());
}

readonly Properties

const settings: {
  theme: "light" | "dark";
  readonly version: number;
} = {
  theme: "dark",
  version: 1,
};

settings.theme = "light";   // ✅
// settings.version = 2;    // ❌ readonly

Index Signature

প্রপার্টির নাম আগে থেকে জানা নেই, তবে ধরন জানা — এমন জায়গায় index signature ব্যবহার হয় (যেমন dictionary/map)।

const scores: { [player: string]: number } = {};
scores["রহিম"] = 95;
scores["করিম"] = 80;

console.log(scores["রহিম"]);   // 95

Nested Objects

const event: {
  title: string;
  date: { start: Date; end: Date };
  location: { city: string; country: string };
} = {
  title: "কনফারেন্স",
  date: {
    start: new Date("2026-01-01"),
    end: new Date("2026-01-02"),
  },
  location: { city: "ঢাকা", country: "বাংলাদেশ" },
};

console.log(event.location.city);   // ঢাকা

Excess Property Checking

object literal সরাসরি typed variable-এ দিলে TypeScript অতিরিক্ত প্রপার্টি (উল্লেখ নেই এমন) ধরে ফেলে। তবে আগে ভেরিয়েবলে রাখলে এই কড়া চেকটি আসে না।

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

// ❌ object literal-এ extra প্রপার্টি
// const u1: User = { name: "রহিম", age: 28, id: 5 };

// ✅ আগে ভেরিয়েবলে রাখলে শুধু প্রাসঙ্গিক অংশ নেয়
const raw = { name: "রহিম", age: 28, id: 5 };
const u2: User = raw;
বড় object-এ alias ব্যবহার করুন

এক-দুই প্রপার্টির জন্য inline annotation দারুণ। বড় object-এর জন্য পরের অধ্যায়ের type alias বা interface ব্যবহারে কোড অনেক পরিষ্কার হবে।

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

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

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

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

mdanamolhasan1998@gmail.com