typescript-strict
1
总安装量
1
周安装量
#53127
全站排名
安装命令
npx skills add https://github.com/oro-ad/nuxt-claude-devtools --skill typescript-strict
Agent 安装分布
mcpjam
1
claude-code
1
kilo
1
junie
1
windsurf
1
zencoder
1
Skill 文档
Enforce strict TypeScript practices:
No any
Never use any. Use unknown for truly unknown types:
// â Avoid
function process(data: any) { }
// â
Better
function process(data: unknown) {
if (typeof data === 'string') {
// Now TypeScript knows it's a string
}
}
Explicit Return Types
Add explicit return types for public/exported functions:
// â
Explicit return type
function calculateTotal(items: Item[]): number {
return items.reduce((sum, item) => sum + item.price, 0)
}
// â
For async functions
async function fetchUser(id: string): Promise<User | null> {
// ...
}
Interface over Type
Prefer interface for object shapes (better error messages, extendable):
// â
Prefer interface
interface User {
id: string
name: string
email: string
}
// Use type for unions, primitives, or complex types
type Status = 'pending' | 'active' | 'done'
type Nullable<T> = T | null
Readonly
Mark immutable data as readonly:
interface Config {
readonly apiUrl: string
readonly maxRetries: number
}
function processItems(items: readonly Item[]) {
// items.push() would be an error
}
Type Guards
Use type guards for runtime type checking:
function isUser(value: unknown): value is User {
return (
typeof value === 'object' &&
value !== null &&
'id' in value &&
'name' in value
)
}
if (isUser(data)) {
// TypeScript knows data is User
console.log(data.name)
}
Const Assertions
Use as const for literal types:
const STATUSES = ['pending', 'active', 'done'] as const
type Status = typeof STATUSES[number] // 'pending' | 'active' | 'done'
Non-null Assertion
Avoid ! when possible. Use optional chaining or type guards:
// â Risky
const name = user!.name
// â
Safer
const name = user?.name ?? 'Unknown'