قابل تلاش، قابل پرنٹ TypeScript حوالہ: ٹائپس، انٹرفیسز، جنرکس، یوٹیلیٹی ٹائپس، نیروئنگ، ڈیکلریشن فائلز اور tsconfig۔ مفت۔

Basic types

14
let name: string = "Ada";
String type annotation
let age: number = 30;
Number (int and float)
let ok: boolean = true;
Boolean
let ids: number[] = [1, 2];
Array of numbers
let pair: [string, number] = ["a", 1];
Tuple: fixed-length typed array
let anything: unknown;
Safe any: must narrow before use
let loose: any;
Opts out of checking (avoid)
function log(): void {}
No return value
function fail(): never { throw new Error(); }
Never returns
let big: bigint = 9007199254740993n;
Arbitrary-precision integer
let id: string | null = null;
Nullable via union
const point = { x: 1 } as const;
Deep readonly literal types
enum Status { Active, Inactive }
Numeric enum
type Dir = "up" | "down";
String literal union (enum-lite)

Interfaces & type aliases

12
interface User { id: number; name: string; }
Object shape contract
type User = { id: number; name: string };
Type alias for a shape
interface User { nickname?: string; }
Optional property
interface User { readonly id: number; }
Property cannot be reassigned
interface Admin extends User { role: string; }
Interface inheritance
type Admin = User & { role: string };
Extend an alias via intersection
interface Dict { [key: string]: number; }
Index signature
interface Fn { (x: number): string; }
Callable interface
interface User { greet(): void; }
Method signature
interface Box<T> { value: T; }
Generic interface
interface Window { myGlobal: string; }
Declaration merging (augment)
type Point = Readonly<{ x: number }>;
Readonly wrapper on an alias

Unions, intersections & narrowing

12
type Id = string | number;
Union: one of several types
type Full = A & B;
Intersection: all members of both
if (typeof id === "string") { ... }
typeof narrowing
if (el instanceof HTMLElement) { ... }
instanceof narrowing
if ("radius" in shape) { ... }
in-operator narrowing
if (value != null) { ... }
Strip null AND undefined
switch (shape.kind) { case "circle": ... }
Discriminated union switch
type Shape = Circle | Square;
Discriminated union (kind field)
const x = cond ? a : b;
Result type is a union of both
user?.address?.city
Optional chaining
const name = input ?? "default";
Nullish coalescing
function assertNever(x: never): never { throw x; }
Exhaustiveness check helper

Generics

11
function first<T>(arr: T[]): T { return arr[0]; }
Generic function
first<string>(["a", "b"])
Explicit type argument
interface Box<T> { value: T; }
Generic interface
class Stack<T> { items: T[] = []; }
Generic class
type Pair<K, V> = { key: K; value: V };
Generic type alias
<T extends { id: number }>
Constrain the type parameter
<T, K extends keyof T>(obj: T, key: K): T[K]
Typed property access
<T = string>
Default type parameter
function wrap<const T>(v: T): T[]
const modifier keeps literals
type Flatten<T> = T extends Array<infer U> ? U : T;
Extract inner type with infer
const map = new Map<string, User>();
Generic built-in collections

Utility types

14
Partial<User>
All properties optional
Required<User>
All properties required
Readonly<User>
All properties readonly
Pick<User, "id" | "name">
Keep only the listed keys
Omit<User, "password">
Drop the listed keys
Record<string, number>
Object map of key to value type
Exclude<T, U>
Remove U members from union T
Extract<T, U>
Keep only U members of union T
NonNullable<T>
Strip null and undefined
ReturnType<typeof fn>
Type a function returns
Parameters<typeof fn>
Tuple of a function's params
Awaited<Promise<string>>
Unwrap promise type → string
InstanceType<typeof MyClass>
Instance type from a class
Uppercase<"id"> / Capitalize<"id">
String-literal case transforms

Functions & overloads

11
function add(a: number, b: number): number
Typed parameters and return
const add = (a: number, b: number) => a + b;
Arrow function (return inferred)
function log(msg: string, level?: string)
Optional parameter
function log(msg: string, level = "info")
Default parameter value
function sum(...nums: number[]): number
Rest parameters
type Handler = (e: Event) => void;
Function type alias
function get(id: number): User; function get(ids: number[]): User[]; function get(x: any): any { ... }
Overload signatures + one impl
function fn(this: HTMLElement, e: Event)
Typed this parameter
async function load(): Promise<User>
Async returns a Promise
function isUser(x: unknown): x is User
Type predicate return
const fn: typeof otherFn = ...;
Reuse another function's type

Classes

12
class User { constructor(public name: string) {} }
Parameter property shorthand
private secret: string;
Compile-time private member
#secret: string;
Runtime private field (ES)
protected id: number;
Visible to subclasses only
readonly createdAt = new Date();
Assign once, in ctor only
static create(): User { return new User(); }
Static factory method
class Admin extends User { ... }
Inheritance (use super())
class Api implements Fetcher { ... }
Implement an interface
abstract class Shape { abstract area(): number; }
Abstract base class
get fullName(): string { return ...; }
Getter accessor
override toString(): string { ... }
Explicit override (safer)
declare id: number;
Declare without initializing

Type guards & assertions

11
function isUser(x: unknown): x is User
Custom type guard
function assertUser(x: unknown): asserts x is User
Assertion function
function assertOk(x: unknown): asserts x
Assert truthy (non-null after)
const el = input as HTMLInputElement;
Type assertion (cast)
value!
Non-null assertion (careful!)
x as unknown as Y
Double assertion (last resort)
const roles = ["admin", "user"] as const;
Literal tuple via const assert
if (Array.isArray(value)) { ... }
Built-in array guard
satisfies Record<string, string>
Check shape, keep inference
typeof x === "object" && x !== null
Safe object check (null trap)
catch (e) { if (e instanceof Error) ... }
Narrow the unknown catch var

Mapped & conditional types

12
type Flags<T> = { [K in keyof T]: boolean };
Mapped type over keys
{ [K in keyof T]?: T[K] }
Add ? modifier (Partial)
{ [K in keyof T]-?: T[K] }
Remove ? modifier (Required)
{ readonly [K in keyof T]: T[K] }
Add readonly to all keys
{ -readonly [K in keyof T]: T[K] }
Strip readonly (Mutable)
{ [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K] }
Key remapping with as
type IsString<T> = T extends string ? true : false;
Conditional type
T extends (infer U)[] ? U : never
infer inside a conditional
type Keys = keyof User;
Union of property names
type Value = User["name"];
Indexed access type
type Route = `/users/${number}`;
Template literal type
T extends any ? T[] : never
Distribute over union members

Modules & declaration files

12
export interface User { ... }
Named export
export default class Api { ... }
Default export
import { User } from "./user";
Named import
import type { User } from "./user";
Type-only import (erased)
export type { User };
Type-only re-export
import * as path from "node:path";
Namespace import
declare module "my-lib" { ... }
Type an untyped package
declare global { interface Window { ... } }
Augment global scope
declare const VERSION: string;
Ambient declaration (.d.ts)
export {};
Force a file to be a module
/// <reference types="node" />
Triple-slash type reference
npm i -D @types/lodash
Install community typings

tsconfig essentials

13
"strict": true
Enable all strict checks (do it)
"target": "ES2022"
Output JavaScript version
"module": "ESNext"
Emitted module system
"moduleResolution": "bundler"
Resolution for Vite/esbuild
"noEmit": true
Type-check only, no output
"esModuleInterop": true
Smooth CommonJS default imports
"skipLibCheck": true
Skip checking .d.ts files
"noUncheckedIndexedAccess": true
arr[i] becomes T | undefined
"paths": { "@/*": ["./src/*"] }
Import path aliases
"outDir": "./dist", "rootDir": "./src"
Output / source directories
"sourceMap": true, "declaration": true
Emit .map and .d.ts files
npx tsc --noEmit
CI type-check command
npx tsc --init
Generate a tsconfig.json

کوئی اندراج “:q” سے میل نہیں کھاتا۔


TypeScript چیٹ شیٹ کے بارے میں

یہ TypeScript چیٹ شیٹ ٹائپ سسٹم کو ایک قابل تلاش صفحے میں سمیٹ دیتی ہے: بنیادی ٹائپس، انٹرفیسز اور ٹائپ ایلیاسز، یونینز، انٹرسیکشنز اور نیروئنگ، جنرکس، بلٹ ان یوٹیلیٹی ٹائپس، فنکشنز اور اوور لوڈز، کلاسز، ٹائپ گارڈز اور اسرشنز، میپڈ اور کنڈیشنل ٹائپس، ماڈیولز اور ڈیکلریشن فائلز، اور tsconfig کے وہ اختیارات جو واقعی اہم ہیں۔

یہ روزمرہ کام کے لیے لکھی گئی ہے: جنرک کنسٹرینٹ کی درست شکل، Pick، Omit، Record اور ReturnType کیا کرتے ہیں، discriminated union کیسے نیرو ہوتا ہے، کاسٹ کے بجائے `satisfies` کب استعمال کرنا چاہیے، تاکہ آپ ہینڈ بک کے لیے اپنا ایڈیٹر چھوڑے بغیر کوئی تفصیل جانچ سکیں۔

اس گروپ کی ہر چیٹ شیٹ کی طرح یہ مفت اور کلائنٹ سائیڈ ہے: سرچ باکس سے قطاروں کو لائیو فلٹر کریں، چپکے رہنے والی فہرست مضامین سے حصوں کے درمیان کودیں، ایک کلک سے کوئی بھی اسنیپٹ کاپی کریں اور اپنی میز پر حوالے کے لیے صفحہ پرنٹ کریں۔

TypeScript چیٹ شیٹ استعمال کرنے کا طریقہ

  1. شیٹ کھولیں اور حصوں پر نظر ڈالیں، Basic types اور Generics سے لے کر tsconfig essentials تک۔
  2. Partial، narrowing یا satisfies جیسا کوئی کلیدی لفظ تلاش کریں تاکہ ہر قطار لائیو فلٹر ہو جائے۔
  3. جب آپ کو ٹائپ لیول کا جدید سنٹیکس چاہیے ہو تو Utility types یا Mapped & conditional types پر جائیں۔
  4. TypeScript کو اپنی کلپ بورڈ پر کاپی کرنے کے لیے کسی اسنیپٹ یا اس کے کاپی آئیکن پر کلک کریں۔
  5. مکمل TypeScript حوالے کی کاغذی کاپی کے لیے Print استعمال کریں۔

اکثر پوچھے جانے والے سوالات

گیارہ حصے: بنیادی ٹائپس، انٹرفیسز اور ٹائپ ایلیاسز، یونینز اور نیروئنگ، جنرکس، یوٹیلیٹی ٹائپس، فنکشنز اور اوور لوڈز، کلاسز، ٹائپ گارڈز اور اسرشنز، میپڈ اور کنڈیشنل ٹائپس، ماڈیولز اور ڈیکلریشن فائلز، اور tsconfig essentials۔

جی ہاں۔ ایک مخصوص حصہ Partial، Required، Readonly، Pick، Omit، Record، Exclude، Extract، ReturnType، Awaited اور باقی سب کا احاطہ کرتا ہے، ہر ایک کے ساتھ ایک سطری وضاحت کے ساتھ۔

بہت زیادہ۔ الگ الگ حصے typeof اور instanceof نیروئنگ، discriminated unions، صارف کے بنائے ٹائپ پریڈیکیٹس، اسرشن فنکشنز اور کاسٹ اور `satisfies` کے درمیان فرق دکھاتے ہیں۔

جی ہاں۔ کسی بھی قطار کے کوڈ یا اس کے کاپی آئیکن پر کلک کریں اور وہ فوراً آپ کی کلپ بورڈ پر کاپی ہو جاتا ہے۔

جی ہاں، یہ مکمل طور پر مفت ہے اور بغیر لاگ ان کے آپ کے براؤزر میں چلتا ہے۔

شیئر کریں

مقبول تلاشیں
typescript چیٹ شیٹ typescript ٹائپس typescript یوٹیلیٹی ٹائپس typescript جنرکس typescript interface بمقابلہ type tsconfig اختیارات typescript حوالہ
مدد چاہیے؟
اس ٹول میں کوئی مسئلہ ملا؟ ہماری ٹیم کو بتائیں۔
مسئلہ رپورٹ کریں

اس مفت ٹول کو اپنی ویب سائٹ پر شامل کریں: نیچے دیا گیا کوڈ کاپی اور پیسٹ کریں۔