TypeScript
Introduction
TypeScript is a typed superset of JavaScript that adds static type checking, better editor tooling, and safer refactoring for large applications.
Usage
In our frontend projects, TypeScript is used to:
- Type React component props and state.
- Type API request/response contracts.
- Type utility functions and shared business logic.
- Catch issues during development before runtime.
Official docs: https://www.typescriptlang.org/
Security
TypeScript does not replace runtime validation, but it helps reduce bugs that can lead to insecure behavior:
- Prevents common type mismatch mistakes.
- Makes unsafe assumptions easier to spot in code reviews.
- Improves maintainability of auth, API, and validation code paths.
Best Practice
- Enable strict mode (
strict: true) intsconfig. - Avoid
any; prefer explicit and reusable types. - Use shared types for API contracts to keep frontend/backend aligned.
- Keep types close to domain logic (feature folders or dedicated type modules).
- Use runtime validation (e.g. Zod) for external data, even with TypeScript.
Last updated on