---
name: Type Hint Expert
slug: type-hint-expert
category: Quality
description: Type Hint Expert explains Python type annotations, including built-in generics, Optional, Protocol, TypedDict, Literal, overload, and TYPE_CHECKING. Use it when adding or reviewing static types in Python code.
github: "https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/typehint"
language: Python
stars: 688
forks: 92
install: "npx degit https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/typehint ~/.claude/skills/typehint"
installs_to: ~/.claude/skills/typehint
source_path: kaiwu/builtin_experts/typehint/SKILL.md
collection_size: 19
category_size: 1354
collection_url: "https://dirskills.com/collections/val1813/kwcode"
added: 2026-08-12T04:43:51.290Z
last_synced: 2026-08-12T04:43:51.290Z
canonical_url: "https://dirskills.com/skills/type-hint-expert"
---

# Type Hint Expert

Type Hint Expert explains Python type annotations, including built-in generics, Optional, Protocol, TypedDict, Literal, overload, and TYPE_CHECKING. Use it when adding or reviewing static types in Python code.

**Install:**

```bash
npx degit https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/typehint ~/.claude/skills/typehint
```

## README

## 领域知识

- Python 3.10+用内置类型（list[str], dict[str, int], str | None），低版本用typing模块
- Optional[X]等价于X | None，表示可能为None，不表示"可选参数"
- 函数签名：所有公开函数标注参数类型和返回类型，内部函数可省略
- 泛型：TypeVar定义类型变量，Generic[T]创建泛型类，bound限制上界
- Protocol：结构化子类型（鸭子类型的静态版），定义接口不需要继承
- TypedDict：字典的精确类型，每个key有独立类型，total=False允许可选key
- Literal：限制值为几个字面量之一，如Literal["read", "write"]
- Callable[[参数类型], 返回类型]标注回调函数，参数多时用Protocol替代
- overload装饰器：同一函数不同参数组合返回不同类型时使用
- TYPE_CHECKING：避免运行时循环导入，仅在类型检查时导入

## 经验规则（自动生成）
