- Home
- Skills
- Flpbalada
- My Opencode Config
- Typescript Best Practices
typescript-best-practices_skill
136
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill flpbalada/my-opencode-config --skill typescript-best-practices- SKILL.md9.7 KB
Overview
This skill guides TypeScript best practices to improve type safety, code organization, and long-term maintainability. It gives actionable recommendations for project configuration, typing strategies, async patterns, testing, and performance. Use it to make concrete decisions when starting projects, reviewing code, or fixing runtime type issues.
How this skill works
The skill inspects typical TypeScript decisions and suggests concrete patterns: enabling strict compiler options, preferring inference for locals and explicit types for public APIs, choosing between interface and type aliases, and replacing any with unknown and generics. It also recommends file organization, async/await patterns, testing-friendly dependency injection, and performance-minded type usage. Outputs are practical, ready-to-apply rules and examples.
When to use it
- Initializing or configuring a new TypeScript project
- Choosing interface vs type alias for public APIs
- Writing or reviewing async/await code and concurrency
- Improving testability and dependency injection in code
- Optimizing type usage for compile-time performance
Best practices
- Enable compiler strict mode (noImplicitAny, strictNullChecks, etc.) for maximum safety
- Trust type inference for local values; annotate public APIs and class members explicitly
- Prefer interface for extendable object shapes and public contracts; use type for unions, tuples, mapped types
- Avoid any; use unknown with type guards or generics to preserve type-safety
- Use guard clauses, single-responsibility functions, and small focused helpers
- Use type-only imports/exports and const assertions to aid tree-shaking and literal typing
Example use cases
- Set up tsconfig.json with strict flags before adding third-party libraries
- Refactor a large function into validation, transformation, persistence, and side-effect steps
- Replace any-typed API responses with unknown and add runtime type guards
- Parallelize independent async calls with Promise.all instead of sequential awaits
- Create barrel files for module groups to simplify imports and surface public types
FAQ
Yes. strict mode catches many errors early and enforces explicit handling of null/undefined and implicit any. It’s the single best compiler configuration for safety.
When should I use interface vs type?
Use interface for extendable object shapes and public contracts; use type for unions, tuples, mapped types, and advanced type compositions.