Documentation
README
TypeScript Best Practices
When to Use
Use this skill when:
- Writing new TypeScript code
- Reviewing TypeScript pull requests
- Refactoring JavaScript to TypeScript
Triggers
Activated when editing .ts or .tsx files in the project.
Rules
Always
- Always use
constfor variables that won't be reassigned - Always use explicit return types on exported functions
- Always prefer
interfaceovertypefor object shapes
Never
- Never use
any— useunknowninstead - Never use
var— useconstorlet - Never ignore TypeScript errors with
@ts-ignore
Examples
// Good: explicit return type
export function calculateTotal(items: Item[]): number {
return items.reduce((sum, item) => sum + item.price, 0);
}
This is the opening of the README. Read the full README on GitHub.