TypeScript: Guides and Practical Know-how | Page 16 | mironsoft Blog
TypeScript
-
Feb 25, 2025
An event handler without a correct type almost automatically tempts you into any or repeated type casts the moment you access event.target.value. React event handler types fix this problem at the root: SyntheticEvent, ChangeEvent, and the matching handler types like MouseEventHandler know exactly which element triggered an event and which properties are available on it. This article shows how to apply React event handler types systematically, without any.
-
Feb 25, 2025
A select component for products, a second one for users, a third for categories, each almost identical, only differing in the data type: this exact pattern is what generic React components solve. Instead of duplicating a component for every data type, the type itself becomes a parameter, and the compiler checks on every use whether data, callback, and rendering fit together. This article shows how generic React components are built in practice, including JSX syntax, constraints, and forwardRef.
-
Feb 15, 2025
Running TypeScript in a monorepo without project references means waiting for a full type check of the entire codebase on every change, with no real type safety enforced between packages. Project references, composite builds, and a shared base configuration create an explicit dependency graph, fast incremental builds, and reliable boundaries between packages, even as the number of packages grows.
-
Feb 7, 2025
composite, references, and tsc --build replace a full recompile with incremental, parallelizable per-package builds.
-
Feb 6, 2025
Template literal types combine string literal types into new literal types, turning loose string parameters into precise, checkable contracts. Event names, CSS class combinations, route paths, and configuration keys can all be validated at compile time, long before a wrong string causes a silent bug at runtime or a customer clicks a broken link.
-
Feb 4, 2025
Bun runs TypeScript files directly, with no need for tsc or a bundler to run first, which noticeably shortens development loops. What matters to understand is that Bun only transpiles TypeScript, stripping types and translating syntax, but performs no type checking, that responsibility still sits with a separate tsc invocation or the IDE.
-
Feb 4, 2025
A poorly designed Component API in a shared component library creates extra work for every team member who uses it. Props without default values, Emits without type contracts, missing slots for composition points and an undocumented Expose interface all make components hard to use. With clear conventions and TypeScript, Component APIs emerge that are stable, extensible and backwards-compatible.
-
Feb 3, 2025
Loading spinner, error message, data: this triangle of state gets typed out almost identically in every component that loads data from an API. A custom hook bundles that pattern in one place before it silently spreads to every component that needs it, and at the same time shows exactly where a hand-rolled solution ends and a library like TanStack Query begins.
-
Jan 29, 2025
Manually maintained TypeScript interfaces for GraphQL types almost inevitably drift out of sync once the schema changes. GraphQL Code Generator solves this problem by generating server resolver types, client operation types and even ready made React hooks directly and automatically from a single schema file.
-
Jan 29, 2025
Running Jest without a clean TypeScript setup gives up the exact safety net you need most, right where errors are most expensive: in tests and mocks. This article shows how ts-jest and babel-jest differ, how to set up a type-safe jest.config.ts, and how to write mock functions, module mocks, and class mocks with real types instead of any.