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. Template Literal Types
TypeScriptAdvanced

Template Literal Types

template literal দিয়ে string টাইপ-স্তরের রচনা, union-এর সাথে combination ও real-world ব্যবহার — বাংলায়।

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

Template literal type হলো string টাইপের ভেতরে template literal (... ${...}) ব্যবহার — যার ফলে string টাইপ-স্তরে গঠিত হতে পারে।

মৌলিক ধারণা

type World = "world";
type Greeting = `hello ${World}`;   // "hello world"

type UserId = `user_${number}`;
const u1: UserId = "user_42";    // ✅
// const u2: UserId = "guest";   // ❌

type Coordinates = `${number}, ${number}`;

Union-এর সাথে Combination

type Vertical = "top" | "bottom";
type Horizontal = "left" | "right";

type Position = `${Vertical}-${Horizontal}`;
// "top-left" | "top-right" | "bottom-left" | "bottom-right"

const pos: Position = "top-right";   // ✅

Intrinsic Modifier

Uppercase, Lowercase, Capitalize, Uncapitalize — এগুলো intrinsic utility যা string টাইপ বদলে দেয়।

type Id = `id_${number}`;
type UppercaseId = Uppercase<Id>;    // `ID_${number}`

type EventType = "click" | "hover" | "scroll";
type HandlerName = `on${Capitalize<EventType>}`;
// "onClick" | "onHover" | "onScroll"

const handler: Record<HandlerName, () => void> = {
  onClick: () => {},
  onHover: () => {},
  onScroll: () => {},
};

Real-world ব্যবহার

// CSS-শৈলী key validation
type CssFont = `font-${"small" | "medium" | "large"}`;

// ইভেন্ট listener প্যাটার্ন
type EventNames = `on${Capitalize<EventType>}`;

function addListener(name: EventNames, fn: () => void): void {
  // ...
}

addListener("onClick", () => console.log("click"));
// addListener("onDoubleClick", fn);   // ❌ টাইপেই আটকায়
জটিলতা সামলান

Template literal types string-কে বিস্তারিত ধরতে লাগে — ছোট ছোট union টাইপে ভেঙে combinations গড়ুন, নাহলে টাইপ explosion হয় (অনেক সম্ভাব্য দান বৃদ্ধি)।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরMapped Types (ম্যাপড টাইপ)পরেরtsconfig.json গভীরে (Compiler Options)
এই পেজে
Tech Tutor

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

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

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

mdanamolhasan1998@gmail.com