Skillipedia article
TypeScript Essentials
Type your JavaScript with interfaces, generics, and strict inference.
Why it matters
TypeScript catches bugs before they ship and documents intent through types.
Core steps
- Enable
strictmode for the best signals. - Define interfaces for data models and prefer readonly where possible.
- Use discriminated unions to model state machines cleanly.
- Add generics to utilities to keep them flexible.
Pattern: Narrowing
type Result = { ok: true; data: string } | { ok: false; error: string };
function handle(result: Result) {
if (result.ok) return result.data;
throw new Error(result.error);
}