Typescript Best Practices
ASecurityUse ES modules and named exports consistently. Replace each `require()` with a static import, use `import type` for type-only dependencies, and give exported functions explicit return types: ```ts // user-service.ts import type { UserRepository } from "./user-repository.js"; export interface User { readonly id: string; } export function getUser(repository: UserRepository, id: string): User { return repository.getById(id); } ``` ```ts // consumer.ts import { getUser } from "./user-service.js";...
- 584 stars
- 0 votes
- 0 copies
- 4 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill typescript-best-practices --agent claude-codeAre you the author of Typescript Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-typescript-best-practices-d41ad278)Use ES modules and named exports consistently. Replace each `require()` with a static import, use `import type` for type-only dependencies, and give exported functions explicit return types:
```ts
// user-service.ts
import type { UserRepository } from "./user-repository.js";
export interface User {
readonly id: string;
}
export function getUser(repository: UserRepository, id: string): User {
return repository.getById(id);
}
```
```ts
// consumer.ts
import { getUser } from "./user-service.js";
import { repository } from "./user-repository.js";
const user = getUser(repository, "u-123");
```
Update consumers from a default import to the named symbol, keep external/internal/relative imports ordered, and configure the package for one module system. Do not replace `require()` with an untyped workaround; use a deliberate dynamic `import()` only when loading must be deferred.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.