TypeScript and JavaScript development standards for modern web and Node.js development. Covers strict TypeScript configuration, type safety patterns, ESM modules, async/await, testing with Jest/Vitest, and security best practices. Use when working with .ts, .tsx, .js, .mjs files, package.json, tsconfig.json, or when asking about TypeScript/JavaScript best practices.
any, use discriminated unionseval, sanitize HTML, validate inputs| Aspect | TypeScript | JavaScript |
|--------|------------|------------|
| Package Manager | pnpm preferred | pnpm preferred |
| Module System | ES Modules | ES Modules + // @ts-check |
| Linting | eslint --max-warnings=0 | eslint --max-warnings=0 |
| Formatting | Prettier | Prettier |
| Types | Strict mode | JSDoc types |
// 1. Use strict equality
if (value === 0) { } // ✅ GOOD
if (value == 0) { } // ❌ BAD
// 2. Handle Promise rejections
fetchData().catch(err => console.error(err)); // ✅ GOOD
// 3. Optional chaining and nullish coalescing
const name = user?.profile?.name ?? 'Guest'; // ✅ GOOD
// 4. Use Set/Map for lookups
const seen = new Set(); // ✅ GOOD (O(1))
const seen = []; // ❌ BAD (O(n))
// 5. Never use eval or new Function
eval(userInput); // ❌ NEVER DO THIS
// 6. Sanitize HTML
element.textContent = userInput; // ✅ GOOD
element.innerHTML = userInput; // ❌ BAD (XSS)
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noUncheckedIndexedAccess": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}
any - Use Proper Types// ❌ BAD - Loses all type safety
function processData(data: any): any {
return data.value;
}
// ✅ GOOD - Generic type
function processData<T>(data: T): T {
return data;
}
// ✅ GOOD - Unknown for truly unknown types
function processData(data: unknown): string {
if (typeof data === 'object' && data !== null && 'value' in data) {
return String((data as { value: unknown }).value);
}
throw new Error('Invalid data');
}
type SuccessResponse = {
status: 'success';
data: { id: string; name: string };
};
type ErrorResponse = {
status: 'error';
error: { code: number; message: string };
};
type ApiResponse = SuccessResponse | ErrorResponse;
function handleResponse(response: ApiResponse): void {
if (response.status === 'success') {
console.log(response.data.id); // Type-safe
} else {
console.log(response.error.message); // Type-safe
}
}
interface User {
id: string;
name: string;
email: string;
password: string;
}
type UserUpdate = Partial<User>; // All optional
type UserCredentials = Pick<User, 'email' | 'password'>;
type UserPublic = Omit<User, 'password'>; // Exclude password
type RequiredUser = Required<User>; // All required
type ReadonlyUser = Readonly<User>; // Immutable
// Parallel execution
const [users, products] = await Promise.all([
fetchUsers(),
fetchProducts()
]);
// Handle partial failures
const results = await Promise.allSettled([
fetchUsers(),
fetchProducts()
]);
results.forEach(result => {
if (result.status === 'fulfilled') {
console.log(result.value);
} else {
console.error(result.reason);
}
});
eval, new Function, or unsanitized innerHTMLtextContent for DOM insertion| Type | Convention | Example |
|------|------------|---------|
| Functions/Variables | camelCase | fetchUserData |
| Classes/Interfaces | PascalCase | UserService |
| Constants | UPPER_SNAKE_CASE | MAX_RETRIES |
| Types | PascalCase | ApiResponse |
npx skills add KiranEswaran/TypeScript 与 JavaScript下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer