技能 typescript-advanced-types
📦

typescript-advanced-types

安全

Master TypeScript Advanced Types

也可從以下取得: wshobson

Build type-safe applications with confidence using TypeScript's powerful type system. Learn generics, conditional types, mapped types, and utility types through practical examples.

支援: Claude Codex Code(CC)
🥉 74 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「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

安全審計

安全
v1 • 2/25/2026

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.

2
已掃描檔案
755
分析行數
0
發現項
1
審計總數
未發現安全問題
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
50
社群
100
安全
91
規範符合性

你能建構什麼

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.

試試這些提示

Basic Generic Function
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.
Conditional Type for Validation
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.
Mapped Type for API Responses
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.
Type-Safe Event System
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?
Use interface for object shapes with better error messages and declaration merging. Use type for unions, intersections, and complex type logic. Both can describe object shapes, but interfaces offer better extensibility.
When should I use generics versus union types?
Use generics when you need type flexibility while maintaining relationships between input and output types. Use union types when a value can be one of several specific types without type relationships.
How do conditional types work in TypeScript?
Conditional types use the extends keyword with a ternary-like syntax: T extends U ? X : Y. They enable type-level logic that selects types based on conditions, similar to if-else at the type level.
What are mapped types and when should I use them?
Mapped types iterate over property keys to transform existing types. Use them for creating variants like Partial, Readonly, or custom transformations that apply uniformly across all properties.
How can I test my TypeScript types?
Create type assertion helpers that verify expected types at compile time. Use patterns like AssertEqual<T, U> that resolve to true for matching types. Test edge cases and ensure type errors occur where expected.
What are template literal types used for?
Template literal types create string-based types with pattern matching. Use them for building type-safe string concatenation, path builders, event names, and enforcing consistent naming conventions.