javascript
javascript
typescript
Why we should use type unknown over any in Typescript?
TypeScript's unknown vs any: both bypass strict typing, but unknown forces you to narrow a value before using it, keeping the safety any throws away. Examples show how each behaves and why unknown is the safer default for untyped data.
typescript
Simplify complicated Typescript - KISS
Simplifying complicated TypeScript with the KISS principle: refactoring examples show when explicit types improve a simple function and when clever type gymnastics make code harder to review, test, and maintain.
Latest
Advanced Switch Case Techniques in TypeScript
TypeScript switch statements can be more than a chain of cases: wrap the switch in a function for cleaner returns, or swap it for an object map for flat, readable branching. Each technique comes with code samples, pros, and cons so you can pick the right one.
Understanding Record type in Typescript
The Record utility type in TypeScript builds object types with fixed keys and value types. A worked example shows Record<Keys, Type> with union keys: restricting IDs to chosen literals and mixing User and AdminUser values, so the compiler flags missing or extra entries.
Understanding TypeScript Function Generators
TypeScript function generators can pause and resume execution, returning values one at a time instead of all at once. What generators are, how yield works in a simple example, and a practical number sum generator that shows where they beat regular functions.
How to deal with infinite scroll in React
Infinite scroll in React gets much easier with react-query: the useInfiniteQuery hook fetches posts page by page, cancels stale requests with AbortSignal, and exposes fetchNextPage for loading more. A complete typed example wrapped in a reusable usePosts hook.
How to simplify TypeScript types and reduce documentation overhead
TypeScript types with many optional fields need comments to explain what goes together. Discriminated unions fix that: split a Task type into per-status variants so invalid combinations fail to compile and the type documents itself. Before and after code included.
Understanding generic types in Typescript
Generic types in TypeScript let one function, class, or interface work safely with many data types. What generics are, how a type parameter beats hardcoding a concrete entity type in a validation helper, and honest pros and cons before you use them everywhere.
Enums with Typescript - why it's bad? Possible solutions
TypeScript enums generate extra JavaScript at compile time and numeric enums are not even type-safe. Why enums can hurt bundle size and correctness, and two safer alternatives: assigning explicit string values or replacing enums with plain objects.