Build type-safe applications with confidence using TypeScript's powerful type system. Learn generics, conditional types, mapped types, and utility types through practical examples.
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「typescript-advanced-types」。 Create a generic merge function that combines two objects and preserves their types
預期結果:
function merge<T, U>(obj1: T, obj2: U): T & U { return { ...obj1, ...obj2 }; }
const result = merge({ name: 'John' }, { age: 30 });
// Type: { name: string } & { age: number }
// Usage: result.name (string), result.age (number)
正在使用「typescript-advanced-types」。 Create a utility type that makes all nested properties readonly
預期結果:
type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends object
? T[P] extends Function ? T[P] : DeepReadonly<T[P]>
: T[P];
};
// Usage: All nested properties become immutable at compile time
安全審計
安全Static analyzer detected 76 patterns but all are false positives. The skill contains documentation-only content with TypeScript code examples in markdown format. No executable code, network calls, or security risks present. All detected patterns are from code snippets used for educational purposes.
品質評分
你能建構什麼
Type-Safe Library Development
Build reusable libraries and frameworks with strong type guarantees that provide excellent developer experience.
Complex API Client Design
Create type-safe API clients with automatic inference of request parameters, response types, and error handling.
Enterprise Application Architecture
Implement robust type systems for large-scale applications with complex data models and state management.
試試這些提示
Create a generic function that accepts any type and returns the same type. Show how TypeScript infers the type automatically and how to explicitly specify it.
Design a conditional type that checks if a type extends another type. Use it to create a type-level validation system for common data types like strings, numbers, and arrays.
Create a mapped type that transforms all properties of an API response type to be optional and readonly. Include key remapping to add getter methods.
Implement a complete type-safe event emitter using generics, conditional types, and template literal types. Support multiple event types with their specific payload types.
最佳實務
- Use unknown instead of any to enforce type checking before operations
- Prefer interface for object shapes and type for unions and complex types
- Leverage TypeScript's type inference and avoid unnecessary type annotations
避免
- Overusing any type which defeats TypeScript's type safety guarantees
- Creating overly complex types that slow down compilation and reduce readability
- Ignoring strict null checks which can lead to runtime errors in production
常見問題
What is the difference between interface and type in TypeScript?
When should I use generics versus union types?
How do conditional types work in TypeScript?
What are mapped types and when should I use them?
How can I test my TypeScript types?
What are template literal types used for?
開發者詳情
作者
sickn33授權
MIT
儲存庫
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/typescript-advanced-types引用
main
檔案結構