Instruction file imported from Nadil-Dulnidu/estava-mobile-app (
.github/instructions/typescript.instructions.md). Copyright stays with the author.
TypeScript strict mode is required. These rules apply to every .ts and .tsx file.
Types
- No
anywithout an explanatory comment justifying why it's unavoidable - No
@ts-ignorewithout an explanatory comment - All exported functions must have explicit return type annotations
- Prefer
typefor object shapes; useinterfaceonly when extension viaextendsis needed - Use
unknowninstead ofanywhen the type is genuinely not known — then narrow it
Naming
- Variables and functions:
camelCase - Types and interfaces:
PascalCase - Module-level constants:
UPPER_SNAKE_CASE - Files:
kebab-case.tsfor utilities,PascalCase.tsfor class/type definitions
Functions
- Maximum 50 lines per function — extract helpers if exceeded
- Single responsibility — one function does one thing
- Pure functions preferred — avoid side effects unless necessary
- No deeply nested callbacks (max 3 levels)
Imports
Order imports in this sequence, each group separated by a blank line:
- External packages (
import ... from 'package') - Framework imports (
import ... from 'sveltekit'/'next'/ etc.) - Internal aliases (
import ... from '$lib/...') - Relative imports (
import ... from './...')
Error Handling
- Never use empty
catchblocks — at minimum log the error - Use typed errors —
catch (error: unknown)then narrow withinstanceof - Fail fast with descriptive messages at system boundaries
- Validate all external input before use — never trust API responses, user input, or file content
Security (API boundaries)
- Validate all user input before processing
- Never pass raw input to file paths, SQL queries, shell commands, or HTML templates
- Use parameterized queries — never string-interpolate into SQL
- Sanitize before rendering dynamic content as HTML