typescript-advanced-types
यह क्या करती है
यह गाइड सिखाती है कि TypeScript के एडवांस फीचर का इस्तेमाल करके ज़्यादा सुरक्षित और लचीला कोड कैसे बनाएँ। इसमें दिखाया गया है कि अलग-अलग डेटा के हिसाब से बदलने वाले types (generics) कैसे बनाएँ, शर्तों के आधार पर बदलने वाले types कैसे बनाएँ, मौजूदा types को कैसे बदलें, और टेक्स्ट पर आधारित types कैसे बनाएँ।
कब इस्तेमाल करें
- ✓जब आप ऐसी code libraries बना रहे हों जिन्हें दूसरे लोग इस्तेमाल करेंगे।
- ✓जब आपको अपने कोड को errors से बहुत सुरक्षित रखना हो।
- ✓जब आप ऐसे जटिल सिस्टम बना रहे हों जहाँ data types साफ तौर पर तय होने चाहिए।
Skill का लिंक
https://github.com/wshobson/agents/blob/main/plugins/javascript-typescript/skills/typescript-advanced-types/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं ऐसा type कैसे बनाऊँ जो केवल numbers या strings स्वीकार करे?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
TypeScript में data types के लिए नियम तय किए जा सकते हैं। Generics और conditional types जैसे फीचर ये नियम अपने-आप और लचीले तरीके से बनाने में मदद करते हैं, ताकि प्रोग्राम चलने से पहले ही सुनिश्चित हो कि इस्तेमाल हो रहा डेटा सही है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
TypeScript Advanced Types
Comprehensive guidance for mastering TypeScript's advanced type system including generics, conditional types, mapped types, template literal types, and utility types for building robust, type-safe applications.
When to Use This Skill
- Building type-safe libraries or frameworks
- Creating reusable generic components
- Implementing complex type inference logic
- Designing type-safe API clients
- Building form validation systems
- Creating strongly-typed configuration objects
- Implementing type-safe state management
- Migrating JavaScript codebases to TypeScript
Core Concepts
1. Generics
Purpose: Create reusable, type-flexible components while maintaining type safety.
Basic Generic Function:
function identity<T>(value: T): T {
return value;
}
const num = identity<number>(42); // Type: number
const str = identity<string>("hello"); // Type: string
const auto = identity(true); // Type inferred: boolean
Generic Constraints:
interface HasLength {
length: number;
}
function logLength<T extends HasLength>(item: T): T {
console.log(item.length);
return item;
}
logLength("hello"); // OK: string has length
logLength([1, 2, 3]); // OK: array has length
logLength({ length: 10 }); // OK: object has length
// logLength(42); // Error: number has no length
Multiple Type Parameters:
function merge<T, U>(obj1: T, obj2: U): T & U {
return { ...obj1, ...obj2 };
}
const merged = merge({ name: "John" }, { age: 30 });
// Type: { name: string } & { age: number }
2. Conditional Types
Purpose: Create types that depend on conditions, enabling sophisticated type logic.
Basic Conditional Type:
type IsString<T> = T extends string ? true : false;
type A = IsString<string>; // true
type B = IsString<number>; // false
Extracting Return Types:
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
function getUser() {
return { id: 1, name: "John" };
}
type User = ReturnType<typeof getUser>;
// Type: { id: number; name: string; }
Distributive Conditional Types:
type ToArray<T> = T extends any ? T[] : never;
type StrOrNumArray = ToArray<string | number>;
// Type: string[] | number[]
Nested Conditions:
type TypeName<T> = T extends string
? "string"
: T extends number
? "number"
: T extends boolean
? "boolean"
: T extends undefined
? "undefined"
: T extends Function
? "function"
: "object";
type T1 = TypeName<string>; // "string"
type T2 = TypeName<() => void>; // "function"
3. Mapped Types
Purpose: Transform existing types by iterating over their properties.
Basic Mapped Type:
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
interface User {
id: number;
name: string;
}
type ReadonlyUser = Readonly<User>;
// Type: { readonly id: number; readonly name: string; }
Optional Properties:
type Partial<T> = {
[P in keyof T]?: T[P];
};
type PartialUser = Partial<User>;
// Type: { id?: number; name?: string; }
Key Remapping:
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};
interface Person {
name: string;
age: number;
}
type PersonGetters = Getters<Person>;
// Type: { getName: () => string; getAge: () => number; }
Filtering Properties:
type PickByType<T, U> = {
[K in keyof T as T[K] extends U ? K : never]: T[K];
};
interface Mixed {
id: number;
name: string;
age: number;
active: boolean;
}
type OnlyNumbers = PickByType<Mixed, number>;
// Type: { id: number; age: number; }
4. Template Literal Types
Purpose: Create string-based types with pattern matching and transformation.
Basic Template Literal:
type EventName = "click" | "focus" | "blur";
type EventHandler = `on${Capitalize<EventName>}`;
// Type: "onClick" | "onFocus" | "onBlur"
String Manipulation:
type UppercaseGreeting = Uppercase<"hello">; // "HELLO"
type LowercaseGreeting = Lowercase<"HELLO">; // "hello"
type CapitalizedName = Capitalize<"john">; // "John"
type UncapitalizedName = Uncapitalize<"John">; // "john"
Path Building:
type Path<T> = T extends object
? {
…
अक्सर पूछे जाने वाले सवाल
Generics क्या हैं?
Generics types के लिए 'placeholder' जैसे होते हैं। इनसे ऐसे functions या classes बनते हैं जो किसी भी data type के साथ काम कर सकें, और फिर भी यह सुनिश्चित रहता है कि इस्तेमाल किया गया type सही है।
Conditional types क्या हैं?
ये ऐसे types हैं जो किसी शर्त के आधार पर अलग तरह से व्यवहार करते हैं। उदाहरण के लिए, कोई type 'true' हो सकता है अगर डेटा string है, और 'false' हो सकता है अगर डेटा number है।
Template literal types किसलिए इस्तेमाल होते हैं?
ये string-based types बनाने देते हैं, जैसे किसी base नाम (`click`) से event नाम (`onClick`) बनाना, या configuration paths को सुरक्षित तरीके से बनाना।
जानकारी
लेखक का मूल विवरण
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.
repo: wshobson/agents
लोकप्रियता
- GitHub स्टार
- 41k
- रैंकिंग में स्थान
- #6715
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
screen-reader-testing
41kआपके एजेंट को screen readers का इस्तेमाल करके वेबसाइटों की जांच करने देता है, ताकि यह पक्का हो सके कि वे accessible हैं।
wcag-audit-patterns
41kआपके एजेंट को वेबसाइटों का accessibility audit करने और WCAG guidelines के हिसाब से समस्याएं ठीक करने में मदद करता है।
multi-reviewer-patterns
41kआपके एजेंट को कई code reviews को एक साथ चलाने देता है। यह एक जैसे findings हटाता है और सारी रिपोर्ट को एक जगह जोड़ता है।
parallel-debugging
41kआपके एजेंट को parallel जांच के साथ जटिल समस्याओं को debug करने और root cause analysis में मदद करता है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।