typescript
This skill should be used when the user asks to "configure TypeScript", "fix type errors", "use dayjs", "add type definitions", "set up React with TypeScript", mentions ".ts" or ".tsx" files, or asks about TypeScript best practices or TypeScript-specific tooling.
When & Why to Use This Skill
This Claude skill optimizes TypeScript development by enforcing strict type safety, consistent code formatting with BiomeJS, and industry best practices. It streamlines the process of configuring TypeScript environments, resolving complex type errors, and maintaining high-quality, readable code through automated alphabetical sorting and standardized type definitions. By prioritizing 'type' over 'interface' and integrating dayjs for date management, it ensures robust and maintainable enterprise-level codebases.
Use Cases
- Project Initialization: Quickly set up React and TypeScript environments with pre-configured best practices, linting rules, and optimized configurations.
- Type Safety & Debugging: Efficiently identify and resolve intricate TypeScript errors while systematically eliminating 'any' types to ensure maximum type coverage.
- Code Standardization: Automatically organize type definitions, object literals, and function parameters alphabetically to enhance team collaboration and code maintainability.
- Date & Time Logic: Implement reliable and readable date calculations using the dayjs library, avoiding the common pitfalls and inconsistencies of the native JavaScript Date object.
- Modern Tooling Integration: Seamlessly adopt BiomeJS for high-performance linting and formatting, ensuring a consistent coding style across large-scale TypeScript projects.
| name | typescript |
|---|---|
| user-invocable | false |
| description | This skill should be used when the user asks to "configure TypeScript", "fix type errors", "use dayjs", "add type definitions", "set up React with TypeScript", mentions ".ts" or ".tsx" files, or asks about TypeScript best practices or TypeScript-specific tooling. |
TypeScript Skill
Rules
Note that these are not hard-and-fast rules. If there's a good reason not to apply a rule, don't apply it.
Alphabetical Order
Maintain alphabetical order for better readability and consistency:
- Function parameters - Order by parameter name
- Object literal fields - Sort by key name
- Type definitions - Arrange fields alphabetically
- Class properties - Order by property name
Example (type definitions):
// bad
type User = {
name: string;
age: number;
email: string;
};
// good
type User = {
age: number;
email: string;
name: string;
};
Biome
Use BiomeJS for linting and formatting JavaScript and TypeScript code. Look for a biome.jsonc file.
Exception: project already uses ESLint and Prettier.
dayjs for date and time calculations
Use the dayjs library for date calculations. Avoid using the native JavaScript Date object.
Example:
import dayjs from "dayjs";
const now = dayjs();
const tomorrow = now.add(1, "day");
No any type
Never use the any type.
Never return a value in forEach callbacks
Example:
[].forEach(() => {
return 1; // bad
});
[].forEach(() => {
// good
});
Another example:
[].forEach((item) => console.log(item)); // bad
[].forEach((item) => {
console.log(item); // good
});
Prefer type instead of interface
Use type instead of interface for declaring types.
Comment Dividers
Use centered comment dividers for major section breaks:
Format (80 chars total):
// -------------------------------------------------------------------------- //
// TITLE //
// -------------------------------------------------------------------------- //
Rules:
- Total width: 80 characters
- Title: UPPERCASE, centered with spaces
- Border line: dashes
-filling the space between//and//
When to use:
- Major logical sections (imports, types, constants, main logic, exports)
- Separating distinct feature areas
- NOT for every function or small grouping
Example:
// -------------------------------------------------------------------------- //
// IMPORTS //
// -------------------------------------------------------------------------- //
import { Effect } from "effect";
// -------------------------------------------------------------------------- //
// TYPES //
// -------------------------------------------------------------------------- //
type Config = {
name: string;
};