آپ parameters اور return value کو type کرتے ہیں، اور TypeScript optional، default، اور rest parameters کی سہولت دیتا ہے۔
ts
(): { a + b; }
(): {
title ? : name;
}
(): { n + by; }
(): {
nums.( a + n, );
}
آپ parameters اور return value کو type کرتے ہیں، اور TypeScript optional، default، اور rest parameters کی سہولت دیتا ہے۔
(): { a + b; }
(): {
title ? : name;
}
(): { n + by; }
(): {
nums.( a + n, );
}
آپ کسی function کی signature کو ایک type کے طور پر بیان کر سکتے ہیں — جو callbacks اور functions رکھنے والے variables کے لیے کارآمد ہے:
type BinaryOp = (a: number, b: number) => number;
const multiply: BinaryOp = (a, b) => a * b; // params inferred from BinaryOp
// callback parameter
function apply(op: (x: number) => number, val: number) { return op(val); }
function parse(x: string): number;
function parse(x: number): string;
function parse(x: any): any { return typeof x === "string" ? +x : String(x); }
functions کو درست طریقے سے type کرنا TypeScript کی قدر کا بنیادی نکتہ ہے — callers کو checked arguments اور معلوم return types ملتے ہیں، optional/default params حقیقی دنیا کی لچک کو ماڈل کرتے ہیں، اور function type aliases higher-order code (callbacks، event handlers، middleware) کو خود وضاحتی اور محفوظ بنا دیتے ہیں۔