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. Variables ও Type Inference
TypeScriptBeginner

Variables ও Type Inference

let, const, explicit type, literal type, const assertion এবং কবে TypeScript নিজে থেকে টাইপ বোঝে — সম্পূর্ণ বাংলায়।

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

TypeScript-এ ভেরিয়েবল লেখার সময় annotation লাগবেই এমন নয় — কারণ compiler নিজেই মান দেখে টাইপ বুঝে নিতে পারে। একেই বলে Type Inference (টাইপ অনুমান)।

let ও const

let score = 0;           // inferred: number
score = 10;              // ✅

const MAX = 100;         // inferred: 100 (literal)
const TAX_RATE = 0.15;   // inferred: 0.15

Type Inference (স্বয়ংক্রিয় টাইপ)

let count = 5 লিখলেই TypeScript বুঝে যায় এটি number। এখানে annotation লেখার প্রয়োজন নেই — কোড পরিষ্কার থাকে।

const first = "রহিম";    // inferred: string
let years = 10;            // inferred: number
const active = true;       // inferred: boolean
const labels = ["গরম", "ঠান্ডা"];  // inferred: string[]

Explicit Types (স্পষ্ট annotation)

কখনো কখনো নিজে টাইপ স্পষ্ট করে দিতে হয় — বিশেষত ফাংশন প্যারামিটার ও API বাউন্ডারিতে।

let grade: string = "A+";
let steps: number[] = [1, 2, 3];
let options: { dark: boolean; theme: string } = {
  dark: true,
  theme: "blue",
};

Literal Types

সাধারণ টাইপ (string) না দিয়ে নির্দিষ্ট মান-ই টাইপ হতে পারে — একে বলে literal type। Union দিয়ে কয়েকটি নির্দিষ্ট মান ধরার অনুমতি দেওয়া যায়।

let mode: "light" | "dark";
mode = "light";    // ✅
// mode = "blue";  // ❌ শুধু light অথবা dark

let httpStatus: 200 | 404 | 500;
httpStatus = 404;   // ✅
// httpStatus = 302;  // ❌

const Assertion

as const দিলে TypeScript মানকে সবচেয়ে সরু literal টাইপে ধরে নেয় — object-এর প্রপার্টিও readonly হয়ে যায়।

const config = {
  name: "server",
  port: 3000,
} as const;

// config.name    // readonly "server"
// config.port = 4000;   // ❌ readonly

const directions = ["up", "down", "left"] as const;
// টাইপ: readonly ["up", "down", "left"]
কোনটি কোথায়?

let পরিবর্তনযোগ্য মানের, const ডিফল্ট। Inference-কে নিজের কাজ করতে দিন — শুধু সেখানে explicit টাইপ লিখুন যেখানে মান বাইরে থেকে আসে (API, configuration, function params)।

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

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

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

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

mdanamolhasan1998@gmail.com